CSS Layout Help - Stretch div to bottom of page

后端 未结 3 1825
天命终不由人
天命终不由人 2020-12-16 13:57

I\'m trying to create a layout with a \'header\' area which contains a logo and some links, and then a content area which needs to extend to the bottom of the page. This is

相关标签:
3条回答
  • 2020-12-16 14:22

    limitations: header height should be static, with an absolute height.

    content height is dynamic.

    CSS code:

    * {
        padding:0;
        margin:0;
    }
    html, body {
        height: 100%;
        color: #fff;
    }
    #header {
        background: red;
        position: absolute;
        z-index:20;
        height: 7em;
        overflow:hidden;
        width:100%;
    }
    #content {
        background: blue;
        position: absolute;
        top: 0;
        padding-top: 7em;
        min-height: 100%;
        box-sizing: border-box;
    }
    

    content stretch all the way to the bottom, even when text is short.

    when content's text is longer than our window height - we get the auto scroll

    Example: http://jsfiddle.net/fixit/p3B4s/3/

    0 讨论(0)
  • 2020-12-16 14:26

    http://jsfiddle.net/CZayc/

    this works by wrapping the header and body in a div to push footer down

    index.html

    <div id="wrap">
        <div id="header">
            header
        </div>
        <div id="main">
            main<br/>main<br/>main<br/>main<br/>main<br/>main<br/>
        </div>
    </div>
    <div id="footer">
        footer
    </div>
    

    style.css

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { 
        margin:0;
        padding:0;
    }
    #header {
        border-top:20px solid #fff;
        height: 33px;
        line-height: 33px;
        text-align: center;
        background-color: green;
    }
    html { height: 100%; }
    body { height: 100%; width: 90%; margin: auto; }
    #wrap { min-height: 100%;background-color:gray;}
    #main {
        overflow: auto;
        padding-bottom: 53px; /* must be same height as the footer */
        background-color: red;
        height: 90%
    }
    #footer {
        position: relative;
        margin-top: -53px; /* negative value of footer height */
        height: 33px;
        line-height: 33px;
        border-bottom:20px solid #fff;
        text-align: center;
        background-color:blue;
    }
    
    0 讨论(0)
  • 2020-12-16 14:27

    Make the container div position:relative and the content div position:absolute. Then give the content div top:<header height> and bottom:0

    Not in a position to test this right now, but I think something like this should work.

    0 讨论(0)
提交回复
热议问题