答案:使用position: fixed将导航栏固定在视窗底部,通过bottom: 0和width: 100%实现全屏贴底,结合flex布局均匀分布导航项,设置z-index确保层级最高,为避免内容被遮挡,主体添加padding-bottom,移动端可优化背景模糊与阴影提升体验。

要实现一个固定在页面底部的导航栏,使用 CSS 非常简单。关键是利用 position: fixed 属性,让导航栏始终停留在视窗底部,不随页面滚动而移动。
1. 基本结构和样式
先写一个简单的 HTML 导航结构:
然后用 CSS 将其固定在底部:
.bottom-nav {position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #fff;
border-top: 1px solid #e0e0e0;
display: flex;
justify-content: space-around;
padding: 10px 0;
z-index: 1000;
}
说明:
立即学习“前端免费学习笔记(深入)”;
- position: fixed 让元素脱离文档流,相对于视窗定位
- bottom: 0 贴住视窗最底部
- width: 100% 撑满整个屏幕宽度
- z-index: 1000 确保导航栏在其他内容之上
- display: flex 让导航项均匀分布
2. 避免内容被遮挡
由于 fixed 元素会覆盖页面内容,底部的内容可能被导航栏挡住。解决方法是给页面主体添加 padding-bottom,留出足够空间:
padding-bottom: 60px; /* 大小与导航栏高度一致 */
}
或者给 或主要容器设置相同的 padding。
3. 适配移动端
在手机上,可以增加一些优化:
- 使用 box-shadow 增加层次感
- 设置 backdrop-filter: blur(10px) 实现毛玻璃效果(可选)
- 确保点击区域足够大,提升触控体验
.bottom-nav {
...
box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
background: rgba(255,255,255,0.9);
backdrop-filter: blur(10px);
}
4. 完整示例关键点
确保导航栏:
- 在所有设备上都贴底显示
- 不影响页面内容阅读
- 视觉清晰,易于点击
- 不会被键盘或其他弹出层顶起(在移动端注意测试)
基本上就这些。固定底部导航栏不复杂,但细节决定体验。










