

新闻资讯
技术学院当页面内容较短时,页脚无法贴底显示,而内容较长时又可能遮挡内容——这是因 `position: absolute` 缺少 `bottom: 0` 导致定位基准缺失;正确设置可实现真正的“粘性页脚”。
要让页脚(
✅ 正确做法是:显式声明 bottom: 0,并确保父容器(body)具备明确的高度上下文:
html, body {
min-height: 100%;
margin: 0; /* 防止默认 body 外边距干扰 */
}
footer {
background-color: #0b2239;
position: absolute;
width: 100%;
bottom: 0; /* ✅ 关键:锚定到容器底端 */
}⚠️ 注意事项:
html, body {
height: 100%;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
main {
flex: 1; /* 占据剩余空间,推页脚到底部 */
}
footer {
background-color: #0b2239;
width: 100%;
}该方式无需绝对定位,天然避免遮挡问题,且响应式友好。总结:bottom: 0 是修复当前问题的最小改动,但 Flexbox 是更可维护、语义更清晰的长期解决方案。