<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%
}
.wrap{
min-height: 100%;
background: #ffc;
text-align: center;
/*开启BFC避免子元素浮动和footer重叠*/
overflow: hidden;
}
.wrap .main{
padding-bottom: 50px;
}
.footer{
height: 50px;
line-height: 50px;
background: #096;
text-align: center;
margin-top: -50px;
}
</style>
</head>
<!--
什么是stickFooter?
经典的"粘连" footer布局
我们有一块内容<main></main>
当main的高度足够长的时候,<footer></footer>应该紧跟在<main></main>元素的后面
当<main></main>元素比较短的时候(比如小于屏幕的高度),我们期望这个<footer></footer>元素能够"粘连"在屏幕的底部
-->
<body>
<div class="wrap">
<div class="main">
<p>main</p>
<p>main</p>
<p>main</p>
<p>main</p>
<p>main</p>
<p>main</p>
<p>main</p>
<p>main</p>
</div>
</div>
<div class="footer">
footer
</div>
</body>
</html>
原文:https://www.cnblogs.com/yitiansanchangyu/p/12317992.html