css让footer永远保持在页面底部

案例1:只保存在页面底部,不固定。

思路:
html:

    <div class="body">
  <header>我是头部</header>
  <div class="content">我是内容</div>
</div>
<footer>我是页脚,我总是固定在页面底部</footer>
        * {
  margin: 0;
  padding: 0;
}
html, body {
  height: 100%; /*让页面撑满窗口*/
}
.body {
  min-height: 100%;
  height: auto !important;
  height: 100%; /*设置页面内容区域最小占满窗口高度*/
  margin: 0 0 -41px; /*利用margin负值留出footer的区域(由于footer设置了1px的border,所以值在原有高度上+1)*/
  text-align: center;
}
footer {
  height: 40px;
  line-height: 40px;
  border-top: 1px solid #ddd;
  text-align: center;

}
        .content{
            width: 100%;
            height: 900px;
        }

固定底部显示:

demo地址:
http://codepen.io/tianzi77/pen/aOrBdb

代码就是添加了

    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;

让他永远在网站底部显示出来!

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值