css底部制作教程
固定底部布局
使用 position: fixed 将元素固定在视窗底部。设置 bottom: 0 确保贴底,width: 100% 保持全宽。适用于页脚、导航栏等需要常驻底部的场景。
.footer {
position: fixed;
bottom: 0;
width: 100%;
background: #333;
color: white;
padding: 10px;
text-align: center;
}
Flexbox 底部布局
通过 Flexbox 实现动态底部布局。为父容器设置 display: flex 和 flex-direction: column,内容区用 flex: 1 自动填充剩余空间,底部自然下压。
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.content {
flex: 1;
}
.footer {
background: #222;
color: white;
padding: 20px;
}
Grid 底部布局
CSS Grid 提供另一种底部控制方式。定义网格模板时预留底部区域,通过 grid-template-rows 分配空间,确保内容与底部分离。
body {
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
header { /* 头部样式 */ }
main { /* 主内容区 */ }
footer {
grid-row: 3;
background: #444;
padding: 15px;
}
响应式底部设计
结合媒体查询调整底部样式。在小屏幕设备上减少内边距或改变布局方向,提升移动端体验。
.footer {
padding: 30px;
display: flex;
justify-content: space-around;
}
@media (max-width: 768px) {
.footer {
padding: 15px;
flex-direction: column;
}
}
底部悬浮效果
添加阴影和过渡动画增强视觉层次。通过 box-shadow 创造悬浮感,transition 实现平滑交互效果。

.footer {
box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
.footer:hover {
box-shadow: 0 -4px 15px rgba(0,0,0,0.2);
}






