Make two divs share the same scrollbar?

前端 未结 2 631
长情又很酷
长情又很酷 2021-02-14 20:32

Given two divs that represent columns embedded in a larger div. If the \"!stuff\" html represents many rows of data that would exceed the height of container, how do I set it u

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 20:42

    You need to set a fixed height for the container, otherwise it will be automatically resized so that the column divs fit inside. The overflow property should only be set for the container, as it is the only element that will be scrolled:

    .container {
        height: 300px;
        width: 100%;
        overflow-x: hidden;
        overflow-y: scroll;
        position: relative;
        padding-bottom: 30px;   
    }
    
    .col1 {
        height: 100%;
        width: 50%;
        position: relative;
        float: left;
    }
    
    .col2 {
        height: 100%;
        width: 50%;
        position: relative;
        float: right;
    }
    

提交回复
热议问题