CSS 底部固定

底部固定的两种理解:
1、无视content多高,footer始终固定在底部,随着浏览器窗口高度的减小会覆盖content内容;
2、在意content高度,当浏览器窗口高度小于或等于content高度时,footer不去覆盖content。
相应解决方案:
1、footer固定定位:
footer{ position: fixed; bottom: 0; left: 0; }
2、footer绝对定位(body相对定位):

body{position:relative;}   /*body相对定位*/
.footer{           /*footer绝对定位*/
    position:absolute;
    bottom:0;
    left:0;
}

但要设置html的高度及body的最小高度,才能撑起来

html{
    height: 100%;
  }
  body{
    min-height: 100%;
  }

写到此,会发现footer覆盖了footer上面的一部分content,且给content设置了margin-bottom,没有效果。
原因:设置了position:absolute,导致margin-bottom无效
解决方法:给content加padding-bottom

content{
	padding-bottom: 一定的值;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值