create a scroll bar in a sidebar

2019-07-14 07:54发布

I'm trying to create a scroll bar inside the #main div so that I can scroll that without scrolling the page or the title but it isn't working. What am I missing?

My code is as follows:

CSS

#topbar {
    height: 40px;
    background-color: blue;
}

#sidebar {
    position: absolute;
    top: 40px;
    bottom: 0px;
    width: 80px;
    overflow: hidden;   
}

#title {
    height:30px;
    background-color: red;
}

#main {
    height: auto;
    overflow: scroll;
}

HTML

<div id="topbar">
    hello
</div>
<div id="sidebar">
    <div id="title">
        title
    </div>
    <div id="main">
        <!-- lots and lots of text-->
    </div>
</div>

You can find an example JSFiddle here: http://jsfiddle.net/PTRCr/

Thanks

标签: css scrollbar
7条回答
太酷不给撩
2楼-- · 2019-07-14 08:51

You need to set height for #main. It is working at http://jsfiddle.net/PTRCr/7/

#main {
    height: 100px;
    overflow-y: scroll;
}
查看更多
登录 后发表回答