页脚置底(sticky footer)就是让网页的footer部分始终在浏览器窗口的底部。
当网页内容足够长以至超出浏览器可视高度时,页脚会随着内容被推到网页底部;
但如果网页内容不够长,置底的页脚就会保持在浏览器窗口底部。

方法一:将内容部分的margin-bottom设为负数
html, body {
margin: 0;
padding: 0;
height: 100%;
}
.wrapper {
min-height: 100%;
margin-bottom: -50px; /* 等于footer的高度 */
}
.footer, .push {
height: 50px;
}这个方法需要容器里有额外的占位元素(
p.push)。-
p.wrapper的margin-bottom需要和p.footer的-height值一样,注意是负height。立即学习“前端免费学习笔记(深入)”;
BEES企业网站管理系统3.4下载主要特性: 1、支持多种语言 BEES支持多种语言,后台添加自动生成,可为每种语言分配网站风格。 2、功能强大灵活 BEES除内置的文章、产品等模型外,还可以自定义生成其它模型,满足不同的需求 3、自定义表单系统 BEES可自定义表单系统,后台按需要生成,将生成的标签加到模板中便可使用。 4、模板制作方便 采用MVC设计模式实现了程序与模板完全分离,分别适合美工和程序员使用。 5、用户体验好 前台
方法二:将页脚的margin-top设为负数
给内容外增加父元素,并让内容部分的
padding-bottom与页脚的height相等。
html, body {
margin: 0;
padding: 0;
height: 100%;
}
.content {
min-height: 100%;
}
.content-inside {
padding: 20px;
padding-bottom: 50px;
}
.footer {
height: 50px;
margin-top: -50px;
}方法三:使用calc()设置内容高度
.content {
min-height: calc(100vh - 70px);
}
.footer {
height: 50px;
}这里假设
p.content和p.footer之间有20px的间距,所以70px=50px+20px
方法四:使用flexbox弹性盒布局
以上三种方法的footer高度都是固定的,如果footer的内容太多则可能会破坏布局。
html {
height: 100%;
}
body {
min-height: 100%;
display: flex;
flex-direction: column;
}
.content {
flex: 1;
}方法五:使用Grid网格布局
html {
height: 100%;
}
body {
min-height: 100%;
display: grid;
grid-template-rows: 1fr auto;
}
.footer {
grid-row-start: 2;
grid-row-end: 3;
}









