代码之家  ›  专栏  ›  技术社区  ›  Dan YOU

高度:100%和粘性页脚布局。最后一场战斗

  •  4
  • Dan YOU  · 技术社区  · 15 年前

    CSS仙境。我的梦想是了解至少100%的粘性页脚和页眉布局。我一直在浏览网页,发现了五种以上不同的方法。

    http://ryanfait.com/sticky-footer/

    http://www.visibilityinherit.com/code/height-stickyfooter-centered.php

    http://www.cssstickyfooter.com/using-sticky-footer-code.html

    http://css-tricks.com/snippets/css/sticky-footer/

    http://bonrouge.com/hcf-fluid.php

    我相信有某种共同点。我要全世界都知道!

    我要求你对这些实践进行深入的比较,并能分辨出每一个实践都包含哪些陷阱。每个布局都可能出现哪些问题?有没有可能用里面的浮球来打破它?我该怎么办?哪些浏览器不包括在内?

    需要示例

    2 回复  |  直到 15 年前
        1
  •  2
  •   detaylor    15 年前

        2
  •  0
  •   Naruto    15 年前

    body, html{
    height: 100%;
    }
    
    body, p {
    margin: 0; padding: 0;
    }   
    
    #wrapper {
    min-height: 100%;
    }
    
    * html #wrapper {
    height: 100%;
    }
    
    
    /*HEADER------------------------------------*/
    #header {
    width: 100%;
    background: #666;
    }
    
    #header_900 {
    width: 960px;
    height: 100px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    }
    
    /*FOOTER------------------------------------*/
    #footer {
    width: 100%;
    height: 100px;
    margin: -100px auto 0 auto; /*THIS SHOULD BE EQUAL TO THE FOOTERS HEIGHT*/
    position: relative;
    background: #666;
    }
    
    #footer_900 {
    width: 960px;
    height: 100px;/*THIS IS THE FOOTERS HEIGHT*/
    position: relative;
    margin: 0 auto;
    }
    
    /*CONTENT------------------------------------*/
    #content {
    width: 100%;
    padding-bottom: 100px; /*THIS SHOULD BE EQUAL TO THE FOOTERS HEIGHT*/
    }
    
    #content_900 {
    width: 960px;
    margin: 0 auto;
    overflow: hidden;
    }
    

    <body>
    
    <div id="wrapper">
    
    
        <div id="header">
            <div id="header_900">
                <p>header</p>
            </div><!--header_900-->
        </div><!--header-->
    
    
        <div id="content">
            <div id="content_900">
                <p>content</p>
            </div><!--content-->
        </div><!--content-->
    
    
    </div><!--wrapper-->
    
    
    <div id="footer">
        <div id="footer_900">
            <p>footer</p>   
        </div><!--footer_900-->
    </div><!--footer-->
    
    
    </body>