用 position: fixed 实现固定底部需设 bottom: 0、width: 100%,并为内容区添加等高 padding-bottom 防遮挡;注意响应式高度同步、移动端 viewport 适配及滚动行为差异。
要实现固定底部(比如页脚始终贴在浏览器窗口最下方),用 position: fixed 是最直接的方式,但需注意它会脱离文档流、可能遮挡内容,新手容易踩坑。关键不是“加了 fixed 就完事”,而是要留出底部空间、处理滚动和响应式兼容。
给页脚元素设置 position: fixed,并指定 bottom: 0 和 left: 0(或 right: 0),同时设 width: 100% 占满整行:
.footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 60px; /* 明确高度,便于预留空间 */
background: https://www./link/93ac0c50dd620dc7b88e5fe05c70e15b333;
color: white;
text-align: center;
}fixed 元素不占布局空间,正文会“顶上来”,导致最后一段文字被页脚盖住。解决方法是在主体内容区域(如 main 或 .content)底部加等高的 padding-botto 或
mmargin-bottom:
padding-bottom:更稳定,不影响外边距塌陷padding-bottom: 60px)fixed 底部默认随滚动始终可见——这正是它的特性,但要注意两点:
viewport meta 控制缩放:
复制即可运行,含基础防遮挡处理:
这里是页面主要内容……
可以很长很长……
© 2025 我的页脚