css sticky footer实现,sticky footer 的几种实现方法

方法一:利用padding和margin

利用margin

DOM 结构

content

sticky footer

CSS

html,body{

height:100%;

}

.content{

min-height:100%;

margin-bottom:-100px;

}

.footer,.content:after{

height:100px; /* 防止动态添加html时造成footer被覆盖 */

}

利用padding,会多一层DOM结构

DOM

CSS

.wrap{

box-sizing:border-box;

min-height:100%;

padding-bottom:100px;

}

main{

min-height:100%;

}

footer{

margin-bottom:-100px;

height:100px;

}

方法二: 利用calc() 属性

.content{

height: calc(100% - 100px);

}

方法三: flex

DOM 结构 同上

CSS

html{

height:100%;

}

html body{

min-height:100%;

display:flex;

flex-direction:column;

}

.content{

flex:1;

}

.footer{

height:100px;

flex:none; /*flex 默认值为0 1 auto */

}

方法四:gird

缺点:兼容性不好

body{

display:grid;

grid-template-rows:80px auto 100px;

}

方法五: 绝对定位

DOM结构(随意)

i am content

CSS

html{

min-height:100%;

position:relative;

}

body{

margin-bottom:100px;

}

.footer{

position:absolute;

height:100px;

width:100%;

bottom:0;

}

方法六:table

兼容所有主流浏览器

DOM 结构

CSS

html,body,.wrap{

height:100%;

}

.wrap{

display:table;

}

header,footer,.main{

display:block; /*IE7 and under*/

display:table-row;

}

header,footer{

height:1

}

暂时整理这么多

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值