什么是 Sticky Footer?
Sticky Footer(粘黏页脚)指的是在页面布局时,当页面的内容不足或等于一屏时,让页脚始终保持在页面的底部,如同粘在底部一样;当页面的内容超过一屏时,即页面发生滚动时,页脚跟随文档,仍然处在页面文档的底部。 简而言之,就是“页脚置底”。
CSS2 实现
效果图
实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<style>
* {
margin: 0;
padding: 0;
font-size: 100px;
}
.wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #ccc;
overflow-y: scroll;
}
.content {
width: 100%;
min-height: 100%;
}
.content-main {
padding-bottom: 100px;
}
.footer {
height: 100px;
background-color: orange;
margin-top: -100px;
}
</style>
</head>
<body>
<!-- 全局容器 -->
<div class="wrapper">
<!-- 内容层 -->
<div class="content">
<div class="content-main">
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<!-- <p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p> -->
</div>
</div>
<!-- Sticky Footer -->
<div class="footer"></div>
</div>
</body>
</html>
flex 实现
效果图
实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<style>
* {
margin: 0;
padding: 0;
font-size: 100px;
}
.container {
min-height: 100vh;
display: flex;
flex-direction: column;
}
.content {
flex: 1;
background-color: #ccc;
}
.footer {
height: 100px;
background-color: orange;
}
</style>
</head>
<body>
<!-- 全局容器 -->
<div class="container">
<!-- 内容层 -->
<div class="content">
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<!-- <p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p>
<p>this is some content</p> -->
</div>
<!-- Sticky Footer -->
<div class="footer"></div>
</div>
</body>
</html>
标签:Footer,some,100px,Sticky,content,background,height,CSS,页面
From: https://www.cnblogs.com/huangtq/p/16882860.html