stricky footer的三种解决方案详解

2020-05-08 08:25:44易采站长站整理

这种方法较为推荐

3.在content的外面添加一个wrapper层

这种方法也是黄轶老师使用的方法,在content的外面添加一个wrapper层包裹


<body>
<div class="content-wrapper clearfix">
<div class="content"></div>
</div>
<div class="footer"></div>
</body>

这种做法为了保证兼容性,我们通常会在wrapper层上添加一个clearfix类,


html,body,.content-wrapper{
height:100%
}
body > .content-wrapper{
height:auto;
min-height:100%;
}
.content{
padding-bottom:150px //与footer的高度相同
}
.footer{
position:relative;
margin-top:-150px; // -`footer高度`
height:150px;
clear:both;
}
.clearfix{
display:inline-block;
}
.clearfix{
content:"";
display:block;
height:0;
clear:both;
visibility: hidden;
}

这样就完成了stricky footer,这种方法也比较推荐,但是加入的代码有点多,而且改变了HTML结构。