css经典布局之stick footer布局

image.png

容器使用负的margin bottom

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>让footer固定在页面顶部</title>
        <style>
            * {
                margin: 0;
            }
            
            html, body {
                height: 100%;
            }
            
            .wrapper {
                min-height: 100%;
                height: auto !important; /* 如果你不需要考虑IE6,则可以把这行与下一行代码删除 */
                height: 100%;
                margin: 0 auto -4em;
            }
            
            .footer, .push {
                height: 4em;
            }
            body{
                text-align: center;
            }
            .footer{
                background-color: #00BBFF;
            }
        </style>
    </head>

    <body>
        <div class="wrapper">
            <h3>你可以通过调整浏览器大小,查看footer的表现</h3>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>

            <div class="push"></div>
        </div>
        <div class="footer">
            <p>Footer</p>
        </div>
    </body>
</html>

底部使用负的margin bottom

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>让footer固定在页面顶部</title>
        <style>
        html, body {
          height: 100%;
          margin: 0;
        }
        .content {
          min-height: 100%;
        }
        .content-inside {
          padding: 20px;
          padding-bottom: 50px;
        }
        .footer {
          height: 50px;
          margin-top: -50px;
          background-color: blue;
        }
        </style>
    </head>

   <body>
  <div class="content">
    <div class="content-inside">
     <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>
            <p>我是占位的</p>

    </div>
  </div>
  <footer class="footer"></footer>
</body>
</html>

转载自:https://w3ctrain.com/2016/06/24/stick-footer/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,693评论 1 92
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,184评论 25 709
  • 如果一定要用一句话来形容你对我的意义,我想我一定会说:你是我的绝世风光,盛世风景。 ——遇见南风,忘了归...
    柒双阅读 3,795评论 0 4
  • 我把我的梦想,写在一片叶子上 它会随着风飘 像云朵儿 像蒲公英 轻盈的落在满载着梦想的航帆上 渡过这海岸口 到达英格兰
    槿年dyt阅读 3,012评论 4 6
  • 左手明媚,右手忧伤。 心中藏锦绣,笔下有洞庭! 郭敬明是个有争议的作家,又或者说商人! 双子座,明显特征是身高,爱...
    闲话星座阅读 1,571评论 0 0

友情链接更多精彩内容