1.設置下邊距爲負值等於底部高度css
css: html
html, body {
height: 100%;
margin: 0
}
.footer {
width: 100%;
background-color: firebrick;
}flex
.content {
min-height: 100%;
margin-bottom: -50px
}flexbox
.push, footer {
height: 50px
}spa
htm:htm
<div class="content">io
<div class="push"></div>
</div>
<div class="footer"></div>class
2.設置上邊距爲負值等於底部高度margin
css:top
html, body {
height: 100%;
margin: 0
}
.footer {
width: 100%;
background-color: firebrick;
height:50px;
margin-top:-50px;
}
.content {
min-height: 100%;
}
.push{
padding-bottom:50px;
}
3.使用flexbox
html{height:100%}
body{min-height:100%;display:flex;flex-direction:column}
.content{flex:1}
.footer{background-color:firebrick;height:50px}
<div class="content">
</div> <div class="footer"></div>