overflow (scroll) - 100% container height

前端 未结 2 1006
独厮守ぢ
独厮守ぢ 2021-02-07 04:24

i\'m trying to have a floated div (call it \'sidebar\') display 100% of container height, and scroll if necessary.

if the sidebar has more content (height) than the cont

2条回答
  •  轮回少年
    2021-02-07 05:07

    Here's CSS styling to accomplish this:

    #container {
        width: 500px;
        border: 3px solid red;
        margin: 0 auto;
        position: relative;
    }
    
    #sidebar {
        position: absolute;
        left: 0;
        top: 0;
        width: 150px;
        height: 100%;
        background-color: yellow;
        overflow-y: scroll;
    }
    
    #main {
        margin-left: 150px;
    }
    
    p, ul {
        padding: 10px;
    }

    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    Live demo: http://jsfiddle.net/TUwej/2/

提交回复
热议问题