Set div to remaining height using CSS with unknown height divs above and below

前端 未结 4 1195
死守一世寂寞
死守一世寂寞 2020-12-04 13:11

Is it possible to make the wrapper fill the window height (no scrolling) and the center div scrollable without messing around with pixels and javascript?

<         


        
4条回答
  •  清歌不尽
    2020-12-04 13:37

    A cross-browser solution derived from Dan Dascalescu answer:

    http://jsfiddle.net/Uc9E2

    html, body {
        margin: 0;
        padding: 0;
        height: 100%;
    }
    .l-fit-height {
        display: table;
        height: 100%;
    }
    .l-fit-height-row {
        display: table-row;
        height: 1px;
    }
    .l-fit-height-row-content {
        /* Firefox requires this */
        display: table-cell;
    }
    .l-fit-height-row-expanded {
        height: 100%;
        display: table-row;
    }
    .l-fit-height-row-expanded > .l-fit-height-row-content {
        height: 100%;
        width: 100%;
    }
    @-moz-document url-prefix() {
        .l-scroll {
            /* Firefox requires this to do the absolute positioning correctly */
            display: inline-block;
        }
    }
    .l-scroll {
        overflow-y: auto;
        position: relative;
        height: 1000px;
    }
    .l-scroll-content {
        position: absolute;
        top: 0;
        bottom: 0;
        height: 1000px;
        min-height:100px;
    }

    Header

    Foo

    Footer

提交回复
热议问题