Scroller with dynamically sized headers/footers

前端 未结 6 614
谎友^
谎友^ 2021-01-07 07:59

What I\'m looking for is to have a container div with any number of headers and footers which would then have another scrolling div in between the

6条回答
  •  难免孤独
    2021-01-07 08:13

    This can now be done using CSS grids pretty easily. without the need of an filler elements even.

    If you want multiple headers, simply put a few divs in there, or make the "header" div a flexbox if that's what you want.

    HTML stays the same:

    Some
    Header
    Content
    Content
    Content
    Content
    ...

    CSS:

    .wrapper{
        height:400px;
        border-left:1px solid red;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: [header] auto [content]1fr [footer]auto;
    }
    .header{
        background-color: #EEE;
        grid-row: header;
    }
    .footer{
        background-color: #EEE;
        grid-row: footer;
    }
    .scroller{
        background-color: #CCC;
        overflow:auto;
        grid-row: content
    }
    

    http://jsfiddle.net/yKTdz/15/

提交回复
热议问题