I have a position: fixed
div in a layout, as a sidebar. I\'ve been asked to have part of it\'s content stay fixed to the top of it (internally), and the rest to
What worked for me :
div#scrollable {
overflow-y: scroll;
max-height: 100vh;
}
Set the scrollable div to have a max-size
and add overflow-y: scroll;
to it's properties.
Edit: trying to get the jsfiddle to work, but it's not scrolling properly. This will take some time to figure out.
It seems to work if you use
div#scrollable {
overflow-y: scroll;
height: 100%;
}
and add padding-bottom: 60px
to div.sidebar
.
For example: http://jsfiddle.net/AKL35/6/
However, I am unsure why it must be 60px
.
Also, you missed the f
from overflow-y: scroll;
I changed scrollable div to be with absolute position, and everything works for me
div.sidebar {
overflow: hidden;
background-color: green;
padding: 5px;
position: fixed;
right: 20px;
width: 40%;
top: 30px;
padding: 20px;
bottom: 30%;
}
div#fixed {
background: #76a7dc;
color: #fff;
height: 30px;
}
div#scrollable {
overflow-y: scroll;
background: lightblue;
position: absolute;
top:55px;
left:20px;
right:20px;
bottom:10px;
}
DEMO with two scrollable divs
Actually this is better way to do that. If height: 100%
is used, the content goes off the border, but when it is 95%
everything is in order:
div#scrollable {
overflow-y: scroll;
height: 95%;
}