本文章从https://www.jb51.net/css/649287.html参考
上图所显示的效果就是sticky Footer,当页面主题内容不够长时,footer定位在窗口的底部,当页面主题内容超出窗口后,footer显示在页面的最底部
1、flex布局方式
html代码:
<body>
<div class="header">标题</div>
<div class="content">
<p>测试文字内容</p>
<p>测试文字内容</p>
<p>测试文字内容</p>
<p>测试文字内容</p>
</div>
<div class="footer">
CopyRight @ 佳发教育 2021
</div>
</body>
css代码:
body { display: flex; flex-flow: column; min-height: 100vh; overflow:auto; }
.main { flex:1; }
2、经典套路:padding-bottom + margin-top方式
html代码:
<div class="wrapper clearfix">
<div class="title">Sticky Footer</div>
<div class="content">
<p>测试文字内容</p>
<p>测试文字内容</p>
<p>测试文字内容</p>
<p>测试文字内容</p>
</div>
</div>
<div class="footer">
CopyRight @ 佳发教育 2021
</div>
css代码:
.wrapper{
min-height: 100vh;
}
.content{
padding-bottom: 50px;
}
.footer{
height: 50px;
margin-top: -50px;
}