zoukankan      html  css  js  c++  java
  • 【转载】CSS Sticky Footer: 完美的CSS绝对底部

    下面是我找到的一个比较完美的方法,来自国外的设计达人,纯CSS,可以实现: 当正文内容很少时,底部位于窗口最下面。当改变窗口高度时,不会出现重叠问题。

    <div id="wrap">
        <div id="main" class="clearfix">
            <div id="content">
            </div>
            <div id="side">
            </div>
        </div>
    </div>
    <div id="footer">
    </div>

    说明: 使用这个布局的前提,就是footer要在总的div容器之外,footer使用一个层,其它所有内容使用一个总的层。如果确实需要到添加其它同级层,那这个同级层就必须使用position:absolute进行绝对定位。

    CSS代码:

    下面是主要的CSS代码,让你的底部可以位于窗口的最下面:

    html, body, #wrap {height: 100%;}
    body > #wrap {height: auto; min-height: 100%;}
    #main {padding-bottom: 150px;}  /* 必须使用和footer相同的高度 */
    #footer {position: relative;
        margin-top: -150px; /* footer高度的负值 */
        height: 150px;
        clear:both;}

    说明: 需要注意的就是#main的padding值、footer的高度和负margin值,需要保持一致。

    就是这么简单,不过还没完。如果你的主体是使用悬浮布局,还得解决一些浏览器的兼容问题,这里使用的重点是为了Goolge Chrome。

    对#main部份进行著名的Clearfix Hack:

    .clearfix:after {content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;}
    .clearfix {display: inline-block;}
    /* Hides from IE-mac */
    * html .clearfix { height: 1%;}
    .clearfix {display: block;}
    /* End hide from IE-mac */

    注: 该方案测试于两栏悬浮布局,兼容各大主流浏览器,包括Google Chrome

    转载自:http://paranimage.com/css-sticky-footer/

  • 相关阅读:
    使用sublimehighlight 将文本 转化html
    iOS- 制作U盘安装Mac OS X 系统
    Win10 UWP vs add github
    Win10 Migrate apps to the Universal Windows Platform (UWP)
    lintcode 刷题记录··
    C# 用tabcontrol实现窗体类似网页排版的显示
    python 爬虫初试
    二叉查找树,查找二维数组
    网页版扫雷游戏···
    C# 读写xml、excel、word、ppt、access
  • 原文地址:https://www.cnblogs.com/hycms/p/3871347.html
Copyright © 2011-2022 走看看