How do I get a vertical scroll bar on an inner div contained in a fixed dimension outer div?

旧巷老猫 提交于 2019-12-06 11:45:30

If it's not an issue to manually set the height of the header you can use absolute positioning on the scroll area and set the top to be the height of the header. I'm araid you are not going to get much closer with pure css.

http://jsfiddle.net/Neograph734/yDJrV/2/

.parent
{
    margin:0px;
    padding:0px;
    height: 400px;
    background-color: orange;
    border: thick purple solid;
    position: relative;
}
.header
{
    font-weight: bold;
    font-size: 28pt;
    font-family: sans-serif,Arial;
    border:yellow thick solid;
}

.scrollContainer
{
    position: absolute;
    border: thick blue solid;
    bottom:0px;
    top:55px; /* This is the header height */
    left:0px;
    right: 0px;

}

.innerScroll
{
    position: absolute;
    overflow-y: auto;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    height: 100%;
}

Update

If javascript is not a problem, you could use this small piece of jquery

var headerHeight = $('.header').outerHeight();
$('.scrollContainer').css('top', headerHeight);

Working example here: http://jsfiddle.net/Neograph734/yDJrV/3/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!