html,
body {
margin: 0;
}
.container {
width: 50%;
margin: 0 auto;
background: #eee;
}
.panel {
width: calc(100% - 140px);
background: lightblue;
height: 100vh;
}
.sidebar {
position: fixed;
right: 0;
top: 0;
width: 120px;
height: 100vh;
text-align: center;
overflow-y: scroll;
background: gold;
}
<div class='container'>
<div class='panel'>
<p>lorem</p>
<p>ipsum</p>
<p>lorem</p>
</div>
<div class='sidebar'>
<p>info</p>
<p>info</p>
<p>info</p>
</div>
</div>
Two problems:
- why
parent
has a top margin? - why
sidebar
is outside ofparent
?
it's probably because of position:fixed
but what is the way to make a sidebar non-movable on a page?
I need it to be fixed because it contains important info about long list items clicked on left side (panel
).
On a large monitor, for example 1920px, the sidebar
is far right, outside of body
(which is 1360px max.)
I need to keep it fixed but tidy inside container
.
` has a `top-margin`. I can't see.
– Aug 27 '18 at 20:16