# 网页布局排版方法总结 - ASCII可视化指南(完整增强版) ## 目录 1. [Grid网格布局模式](#一grid网格布局模式) 2. [Flexbox布局模式](#二flexbox布局模式) 3. [图层叠加与定位模式](#三图层叠加与定位模式) 4. [响应式布局转换](#四响应式布局转换) 5. [间距系统对比](#五间距系统对比) 6. [排版层次结构](#六排版层次结构) 7. [实用布局组合示例](#七实用布局组合示例) 8. [Hero区域布局模式](#八hero区域布局模式) ⭐ 新增 9. [导航栏布局模式](#九导航栏布局模式) ⭐ 新增 10. [Agent头像区布局](#十agent头像区布局) ⭐ 新增 11. [Stats统计数据布局](#十一stats统计数据布局) ⭐ 新增 12. [Footer总结区布局](#十二footer总结区布局) ⭐ 新增 13. [关键CSS属性速查表](#十三关键css属性速查表) 14. [常见问题解决方案](#十四常见问题解决方案) 15. [最佳实践总结](#十五最佳实践总结) --- ## 一、Grid网格布局模式 ### 1. Grid-2 布局(2列并排) ``` ┌─────────────────────────────────────────────────────────────┐ │ 容器 (.grid-2) │ │ grid-template-columns: repeat(2, 1fr) │ ├─────────────────────────────┬───────────────────────────────┤ │ │ │ │ 卡片 1 │ 卡片 2 │ │ (50% 宽度) │ (50% 宽度) │ │ │ │ │ ┌─────────────┐ │ ┌─────────────┐ │ │ │ 图片 │ │ │ 图片 │ │ │ │ 16:9 比例 │ │ │ 16:9 比例 │ │ │ └─────────────┘ │ └─────────────┘ │ │ ┌─────────────┐ │ ┌─────────────┐ │ │ │ 标题 │ │ │ 标题 │ │ │ ├─────────────┤ │ ├─────────────┤ │ │ │ 内容 │ │ │ 内容 │ │ │ └─────────────┘ │ └─────────────┘ │ │ │ │ └─────────────────────────────┴───────────────────────────────┘ CSS 代码: .grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--spacing-2xl); } 适用场景: - 对比展示(如:功能对比、前后对比) - 大尺寸内容展示 - 左右分栏布局 ``` ### 2. Grid-3 布局(3列并排) ``` ┌───────────────────────────────────────────────────────────────────────────┐ │ 容器 (.grid-3) │ │ grid-template-columns: repeat(3, 1fr) │ ├───────────────────────┬───────────────────────┬───────────────────────────┤ │ │ │ │ │ 卡片 1 │ 卡片 2 │ 卡片 3 │ │ (33.33% 宽度) │ (33.33% 宽度) │ (33.33% 宽度) │ │ │ │ │ │ ┌─────────┐ │ ┌─────────┐ │ ┌─────────┐ │ │ │ 图片 │ │ │ 图片 │ │ │ 图片 │ │ │ │ 16:9 │ │ │ 16:9 │ │ │ 16:9 │ │ │ └─────────┘ │ └─────────┘ │ └─────────┘ │ │ ┌─────────┐ │ ┌─────────┐ │ ┌─────────┐ │ │ │ 标题 │ │ │ 标题 │ │ │ 标题 │ │ │ ├─────────┤ │ ├─────────┤ │ ├─────────┤ │ │ │ 内容 │ │ │ 内容 │ │ │ 内容 │ │ │ └─────────┘ │ └─────────┘ │ └─────────┘ │ │ │ │ │ └───────────────────────┴───────────────────────┴───────────────────────────┘ CSS 代码: .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--spacing-2xl); } 适用场景: - 三要素展示(如:特点、优势、功能) - 项目案例展示 - 服务项目列表 - 成果展示区 ``` ### 3. Grid-4 布局(4列并排) ``` ┌─────────────────────────────────────────────────────────────────────────────────────────┐ │ 容器 (.grid-4) │ │ grid-template-columns: repeat(4, 1fr) │ ├──────────────────┬──────────────────┬──────────────────┬──────────────────────────────┤ │ │ │ │ │ │ 卡片 1 │ 卡片 2 │ 卡片 3 │ 卡片 4 │ │ (25% 宽度) │ (25% 宽度) │ (25% 宽度) │ (25% 宽度) │ │ │ │ │ │ │ ┌────────┐ │ ┌────────┐ │ ┌────────┐ │ ┌────────┐ │ │ │ 图片 │ │ │ 图片 │ │ │ 图片 │ │ │ 图片 │ │ │ │ 3:2 │ │ │ 3:2 │ │ │ 3:2 │ │ │ 3:2 │ │ │ └────────┘ │ └────────┘ │ └────────┘ │ └────────┘ │ │ ┌────────┐ │ ┌────────┐ │ ┌────────┐ │ ┌────────┐ │ │ │ 标题 │ │ │ 标题 │ │ │ 标题 │ │ │ 标题 │ │ │ └────────┘ │ └────────┘ │ └────────┘ │ └────────┘ │ │ │ │ │ │ └──────────────────┴──────────────────┴──────────────────┴──────────────────────────────┘ CSS 代码: .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--spacing-xl); } 适用场景: - 数据统计展示 - 产品特性列表 - 设计原则说明 - 快速功能预览 ⚠️ 注意:避免3+1布局(3个一行,1个换行) ❌ 错误: ┌─────┬─────┬─────┐ │ 1 │ 2 │ 3 │ └─────┴─────┴─────┘ ┌─────┐ │ 4 │ ← 单独换行很丑 └─────┘ ✅ 正确: ┌────┬────┬────┬────┐ │ 1 │ 2 │ 3 │ 4 │ └────┴────┴────┴────┘ ``` ### 4. 食品紧凑版Grid优化(减少列数,增大单元格) ``` 标准版 Grid-3: 食品紧凑版 Grid-3: ┌────┬────┬────┐ ┌──────────┬──────────┐ │ 1 │ 2 │ 3 │ │ 1 │ 2 │ └────┴────┴────┘ └──────────┴──────────┘ ┌──────────┐ │ 3 │ └──────────┘ grid-3 { grid-3 { columns: repeat(3, 1fr) columns: repeat(2, 1fr) ← 改为2列 } } 优势: - 图片更大,内容更突出 - 减少拥挤感 - 提升视觉层次 ``` --- ## 二、Flexbox布局模式 ### 1. Hero浮动卡片(强制并排) ``` ┌──────────────────────────────────────────────────────────────┐ │ Hero 内容区域 │ │ │ │ ┌──────────────┐ │ │ │ 主标题 │ │ │ │ 副标题 │ │ │ └──────────────┘ │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ 3600片 │ │ 99.7% │ │ ±0.02mm │ │ 300ms │ │ │ │ /小时 │ │ 检出率 │ │ 精度 │ │ 时间 │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │ ← flex-wrap: nowrap 强制并排,不换行 │ └──────────────────────────────────────────────────────────────┘ CSS 代码: .hero-floating-cards { display: flex; gap: var(--spacing-md); /* 紧凑间距 */ justify-content: center; flex-wrap: nowrap; /* 关键:强制并排 */ } .hero-card { padding: var(--spacing-sm) var(--spacing-md); /* 紧凑内边距 */ min-width: 100px; /* 小尺寸 */ border-radius: var(--radius-md); /* 适中圆角 */ } 关键技术点: ✅ flex-wrap: nowrap → 强制单行显示 ✅ gap 使用 md 而非 lg → 节省空间 ✅ min-width 100px → 保持紧凑 ❌ flex-wrap: wrap → 会导致换行 ``` ### 2. 卡片内部Flexbox Order布局 ``` 传统布局(标题在上): Order重排布局(图片优先): ┌─────────────────┐ ┌─────────────────┐ │ .card-header │ ← order: 1 │ .image │ ← order: 1 │ 标题区域 │ │ ┌───────────┐ │ ├─────────────────┤ │ │ 图片 │ │ │ .image │ ← order: 2 │ │ 16:9比例 │ │ │ ┌───────────┐ │ │ └───────────┘ │ │ │ 图片 │ │ ├─────────────────┤ │ └───────────┘ │ │ .card-header │ ← order: 2 ├─────────────────┤ │ 标题区域 │ │ .card-body │ ← order: 3 ├─────────────────┤ │ 内容区域 │ │ .card-body │ ← order: 3 └─────────────────┘ │ 内容区域 │ └─────────────────┘ CSS 代码: .card { display: flex; flex-direction: column; padding: 0; /* 移除内边距,让图片占满 */ } .image-container { order: 1; /* 图片最前 */ aspect-ratio: 16/9; margin-bottom: 0; /* 无间距 */ border-radius: 0; /* 卡片内无圆角 */ } .card-header { order: 2; /* 标题居中 */ padding: var(--spacing-xl); } .card-body { order: 3; /* 内容最后 */ padding: var(--spacing-xl); flex: 1; /* 占据剩余空间 */ } 优势: - 视觉冲击力强 - 图片优先展示 - 灵活调整顺序 - 响应式友好 ``` ### 3. 图片容器Aspect Ratio控制 ``` 16:9 宽屏比例(食品/能源页面常用): ┌────────────────────────────────────┐ │ │ │ ┌──────────────┐ │ │ │ │ │ ← height: 自动计算 │ │ 16:9 │ │ (width / 16 * 9) │ │ │ │ │ └──────────────┘ │ │ │ └────────────────────────────────────┘ width: 100% 3:2 标准比例(产品展示): ┌──────────────────────┐ │ │ │ ┌──────────┐ │ │ │ │ │ ← height: 自动计算 │ │ 3:2 │ │ (width / 3 * 2) │ │ │ │ │ └──────────┘ │ │ │ └──────────────────────┘ width: 100% 4:3 传统比例(时间线图片): ┌─────────────────┐ │ │ │ ┌─────────┐ │ │ │ │ │ ← height: 自动计算 │ │ 4:3 │ │ (width / 4 * 3) │ │ │ │ │ └─────────┘ │ │ │ └─────────────────┘ width: 100% CSS 代码: /* 16:9 宽屏 - 紧凑现代 */ .image-container { aspect-ratio: 16/9; width: 100%; object-fit: cover; } /* 3:2 标准 - 产品展示 */ .product-image { aspect-ratio: 3/2; width: 100%; } /* 4:3 传统 - 时间线 */ .timeline-image { aspect-ratio: 4/3; flex: 0 0 300px; } 关键点: ✅ aspect-ratio 自动计算高度 ✅ object-fit: cover 裁剪适应 ✅ 无需手动设置 height ``` --- ## 三、图层叠加与定位模式 ### 1. 背景图片+渐变叠加 ``` ┌─────────────────────────────────────────┐ │ 卡片标题区域 (.card-header) │ ├─────────────────────────────────────────┤ │ ┌─────────────────────────────────────┐ │ ← position: relative │ │ 【Layer 3 - 最上层】 │ │ (容器定位上下文) │ │
描述内容... │ │ │
│ ┃ └──────────────────┘ │ │
│ ●───────────────────────────────────────────────────────┘ │
│ ┃ │
│ ●───────────────────────────────────────────────────────┐ │
│ ┃ ┌──────────────────┐ ┌──────────────────┐ │ │
│ ┃ │ 时间线图片 │ │ 时间线内容 │ │ │
│ ┃ └──────────────────┘ └──────────────────┘ │ │
│ ●───────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────┘
← 3px渐变线条
CSS 关键点:
.timeline-layout::before {
position: absolute;
left: 0;
width: 3px;
background: linear-gradient(
to bottom,
var(--primary-green),
var(--accent-gold)
);
}
.timeline-dot {
position: absolute;
left: calc(-1 * var(--spacing-2xl) - 8px);
width: 20px;
height: 20px;
border-radius: 50%;
}
```
### 2. Featured Grid(高亮第一项)
```
┌─────────────────────────────────────────────────────────┐
│ Featured Grid 布局 │
├─────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────┐ ┌─────────┐ │
│ │ │ │ │ │ │ │
│ │ │ │ Item2 │ │ Item3 │ │
│ │ Featured │ │ │ │ │ │
│ │ Item 1 │ │ 3:2 │ │ 3:2 │ │
│ │ (grid-row: │ └─────────┘ └─────────┘ │
│ │ 1/3) │ │
│ │ 3/4 比例 │ ┌─────────┐ ┌─────────┐ │
│ │ │ │ │ │ │ │
│ │ │ │ Item4 │ │ Item5 │ │
│ │ │ │ │ │ │ │
│ └─────────────────┘ └─────────┘ └─────────┘ │
│ ← span 2 rows │
└─────────────────────────────────────────────────────────┘
CSS 代码:
.featured-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.featured-item:first-child {
grid-column: 1 / 2; /* 占第1列 */
grid-row: 1 / 3; /* 跨2行 */
}
.featured-item:first-child .featured-image {
aspect-ratio: 3/4; /* 竖向比例 */
}
```
---
## 八、Hero区域布局模式 ⭐
### 1. 标准Hero布局
```
┌────────────────────────────────────────────────────────────────┐
│ Hero Section │
│ (min-height: 60vh) │
│ │
│ ┌──────────────────────┐ │
│ │ 🔬 化工订单班 │ ← Badge徽章 │
│ └──────────────────────┘ │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ 半导体AI综合检测项目 │ ← 主标题 │
│ │ (text-5xl, font-bold) │ │
│ └──────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ 300mm硅晶圆 + SiO₂薄膜智能质检 │ ← 副标题 │
│ │ (text-2xl, font-normal) │ │
│ └──────────────────────────────────────┘ │
│ │
│ ┌─────────────────────┐ │
│ │ 🤖 AI驱动全流程 │ ← 描述列表 │
│ │ 🔬 4大Agent协同 │ │
│ │ ✅ 95%合格率 │ │
│ └─────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────┘
CSS 代码:
.hero {
min-height: 60vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
background: linear-gradient(135deg, var(--primary), var(--secondary));
position: relative;
overflow: hidden;
}
.hero-content {
max-width: 800px;
padding: var(--spacing-3xl) var(--spacing-xl);
z-index: 1;
}
.hero-badge {
display: inline-block;
padding: var(--spacing-xs) var(--spacing-md);
background: rgba(255, 255, 255, 0.2);
border-radius: var(--radius-full);
backdrop-filter: blur(10px);
margin-bottom: var(--spacing-lg);
}
.hero-title {
font-size: var(--text-5xl);
font-weight: var(--font-bold);
line-height: 1.1;
margin-bottom: var(--spacing-md);
}
.hero-subtitle {
font-size: var(--text-2xl);
opacity: 0.9;
margin-bottom: var(--spacing-xl);
}
.hero-description {
font-size: var(--text-lg);
line-height: 1.8;
opacity: 0.8;
}
关键点:
✅ 徽章采用玻璃态效果
✅ 标题层次清晰(5xl → 2xl → lg)
✅ 背景使用渐变色
✅ 居中对齐,最大宽度限制
```
### 2. Hero浮动卡片变体(数据展示型)
```
┌────────────────────────────────────────────────────────────────┐
│ Hero Section │
│ │
│ ┌────────────────────────┐ │
│ │ 项目标题区域 │ │
│ └────────────────────────┘ │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ ┌────────┐ │ │ ┌────────┐ │ │ ┌────────┐ │ │ ┌────────┐ │ │
│ │ │ 3600片 │ │ │ │ 99.7% │ │ │ │±0.02mm │ │ │ │ 300ms │ │ │
│ │ │ /小时 │ │ │ │ 检出率 │ │ │ │ 精度 │ │ │ │ 时间 │ │ │
│ │ └────────┘ │ │ └────────┘ │ │ └────────┘ │ │ └────────┘ │ │
│ │ Icon图标 │ │ Icon图标 │ │ Icon图标 │ │ Icon图标 │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
│ ← Flexbox并排,nowrap强制不换行 │
│ │
└────────────────────────────────────────────────────────────────┘
CSS 代码:
.hero-floating-cards {
display: flex;
gap: var(--spacing-md);
justify-content: center;
flex-wrap: nowrap; /* 关键:强制并排 */
margin-top: var(--spacing-2xl);
}
.hero-card {
min-width: 120px;
padding: var(--spacing-md) var(--spacing-lg);
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(15px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: var(--radius-lg);
text-align: center;
transition: transform 0.3s ease;
}
.hero-card:hover {
transform: translateY(-5px);
}
.hero-card-value {
font-size: var(--text-3xl);
font-weight: var(--font-bold);
margin-bottom: var(--spacing-xs);
}
.hero-card-label {
font-size: var(--text-sm);
opacity: 0.8;
}
```
---
## 九、导航栏布局模式 ⭐
### 1. 水平滚动导航(订单班标准)
```
┌────────────────────────────────────────────────────────────────┐
│ 导航栏 (position: sticky) │
├────────────────────────────────────────────────────────────────┤
│ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ >>> │
│ │ 📄项目 │ │ 🎯判定 │ │ 🔬检测 │ │ 📊结果 │ │ 💡总结 │ │
│ │ 概述 │ │ 标准 │ │ 流程 │ │ 分析 │ │ 建议 │ │
│ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │
│ │
│ ← overflow-x: auto 水平滚动 │
│ ← flex-wrap: nowrap 强制单行 │
└────────────────────────────────────────────────────────────────┘
移动端滚动提示:
┌────────────────────────────────────────────────────────────────┐
│ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ▶▶▶ │
│ │ 概述 │ │ 标准 │ │ 流程 │ │ 结果 │ │
│ └──────┘ └──────┘ └──────┘ └──────┘ │
│ ← 左右滑动查看更多 │
└────────────────────────────────────────────────────────────────┘
CSS 代码:
.nav {
position: sticky;
top: 0;
z-index: 100;
background: var(--bg-semi-dark);
backdrop-filter: blur(20px);
border-bottom: 1px solid var(--border);
overflow-x: auto;
overflow-y: hidden;
-webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
}
.nav-container {
display: flex;
gap: var(--spacing-sm);
padding: var(--spacing-md) var(--spacing-lg);
flex-wrap: nowrap; /* 强制单行 */
min-width: min-content;
}
.nav-item {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--spacing-xs);
padding: var(--spacing-sm) var(--spacing-md);
border-radius: var(--radius-md);
white-space: nowrap; /* 防止文字换行 */
cursor: pointer;
transition: all 0.3s ease;
}
.nav-item.active {
background: var(--primary);
color: white;
}
.nav-item:hover {
background: var(--bg-hover);
}
/* 隐藏滚动条但保留功能 */
.nav::-webkit-scrollbar {
display: none;
}
.nav {
-ms-overflow-style: none;
scrollbar-width: none;
}
关键点:
✅ sticky定位,滚动时固定顶部
✅ overflow-x: auto 支持水平滚动
✅ flex-wrap: nowrap 强制单行
✅ backdrop-filter 玻璃态效果
✅ 隐藏滚动条保持美观
```
### 2. 导航项结构详解
```
单个导航项内部结构:
┌──────────────────┐
│ .nav-item │
│ ┌────────────┐ │
│ │ Icon图标 │ │ ←
│ └────────────┘ │
│ ┌────────────┐ │
│ │ 文字标签 │ │ ←
│ └────────────┘ │
└──────────────────┘
flex-direction: column
align-items: center
激活状态:
┌──────────────────┐
│ .nav-item.active │ ← 背景色变化
│ ┌────────────┐ │
│ │ 🔵 Icon │ │ ← 图标高亮
│ └────────────┘ │
│ ┌────────────┐ │
│ │ 项目概述 │ │ ← 文字加粗
│ └────────────┘ │
└──────────────────┘
background: var(--primary)
color: white
font-weight: 600
```
---
## 十、Agent头像区布局 ⭐
### 1. Section Header布局(Agent信息)
```
┌────────────────────────────────────────────────────────────────┐
│ Section Header │
├────────────────────────────────────────────────────────────────┤
│ ┌─────────┐ ┌────────────────────────────────────────┐ │
│ │ │ │ .agent-info │ │
│ │ Agent │ │ ┌──────────────────────────────────┐ │ │
│ │ 头像 │ │ │ 👤 环境咨询师 │ │ │
│ │ (80px) │ │ │ (.agent-name) │ │ │
│ │ │ │ └──────────────────────────────────┘ │ │
│ │ 圆形 │ │ │ │
│ └─────────┘ │ ┌──────────────────────────────────┐ │ │
│ │ │ 项目背景与需求分析 │ │ │
│ │ │ (.section-title, text-4xl) │ │ │
│ │ └──────────────────────────────────┘ │ │
│ └────────────────────────────────────────┘ │
│ ← Flexbox横向排列,头像在左,信息在右 │
└────────────────────────────────────────────────────────────────┘
CSS 代码:
.section-header {
display: flex;
align-items: center;
gap: var(--spacing-xl);
margin-bottom: var(--spacing-2xl);
padding-bottom: var(--spacing-xl);
border-bottom: 2px solid var(--border);
}
.agent-avatar {
width: 80px;
height: 80px;
border-radius: 50%;
object-fit: cover;
border: 3px solid var(--primary);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
flex-shrink: 0; /* 防止被压缩 */
}
.agent-info {
flex: 1;
}
.agent-name {
display: flex;
align-items: center;
gap: var(--spacing-sm);
font-size: var(--text-lg);
font-weight: var(--font-semibold);
color: var(--primary);
margin-bottom: var(--spacing-xs);
}
.section-title {
font-size: var(--text-4xl);
font-weight: var(--font-bold);
line-height: 1.2;
margin: 0;
}
关键点:
✅ Flexbox横向布局
✅ 头像圆形,带边框和阴影
✅ gap间距清晰分隔
✅ Agent名称带图标
✅ 底部边框分隔区域
```
### 2. 响应式Agent Header
```
桌面端(>768px):
┌──────────────────────────────────────────────┐
│ ┌─────┐ ┌──────────────────────────────┐ │
│ │头像 │ │ 👤 环境咨询师 │ │
│ │80px │ │ 项目背景与需求分析 │ │
│ └─────┘ └──────────────────────────────┘ │
└──────────────────────────────────────────────┘
flex-direction: row
移动端(≤768px):
┌──────────────────────────────────────────────┐
│ ┌─────────┐ │
│ │ 头像 │ │
│ │ 60px │ │
│ └─────────┘ │
│ ┌─────────────────┐ │
│ │ 👤 环境咨询师 │ │
│ │ 项目背景 │ │
│ └─────────────────┘ │
└──────────────────────────────────────────────┘
flex-direction: column
align-items: center
text-align: center
@media (max-width: 768px) {
.section-header {
flex-direction: column;
align-items: center;
text-align: center;
}
.agent-avatar {
width: 60px;
height: 60px;
}
.section-title {
font-size: var(--text-3xl);
}
}
```
---
## 十一、Stats统计数据布局 ⭐
### 1. 标准Stats布局(4项并排)
```
┌────────────────────────────────────────────────────────────────┐
│ 统计数据区 (.stats) │
├────────────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ │ │ │ │ │ │ │ │
│ │ 项目总预算 │ │ 监测频次 │ │ 监测指标 │ │ 样品总数 │ │
│ │ (.stat- │ │ (.stat- │ │ (.stat- │ │ (.stat- │ │
│ │ label) │ │ label) │ │ label) │ │ label) │ │
│ │ │ │ │ │ │ │ │ │
│ │ 45万元 │ │ 12次/年 │ │ 26项 │ │ 144个/年 │ │
│ │ (.stat- │ │ (.stat- │ │ (.stat- │ │ (.stat- │ │
│ │ value) │ │ value) │ │ value) │ │ value) │ │
│ │ │ │ │ │ │ │ │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ← grid-template-columns: repeat(4, 1fr) │
└────────────────────────────────────────────────────────────────┘
CSS 代码:
.stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: var(--spacing-xl);
margin-top: var(--spacing-2xl);
padding: var(--spacing-xl);
background: var(--bg-semi-dark);
border-radius: var(--radius-lg);
}
.stat-item {
text-align: center;
padding: var(--spacing-lg);
background: var(--bg-card);
border-radius: var(--radius-md);
border: 1px solid var(--border);
transition: all 0.3s ease;
}
.stat-item:hover {
transform: translateY(-5px);
box-shadow: var(--shadow-lg);
}
.stat-label {
font-size: var(--text-sm);
color: var(--text-gray);
margin-bottom: var(--spacing-sm);
text-transform: uppercase;
letter-spacing: 0.05em;
}
.stat-value {
font-size: var(--text-3xl);
font-weight: var(--font-bold);
color: var(--primary);
line-height: 1.2;
}
关键点:
✅ Grid 4列等宽布局
✅ 标签小字,数值大字
✅ 悬停上移效果
✅ 卡片样式分隔
```
### 2. 响应式Stats布局
```
桌面端(>1024px):
┌─────┬─────┬─────┬─────┐
│ 1 │ 2 │ 3 │ 4 │
└─────┴─────┴─────┴─────┘
grid-template-columns: repeat(4, 1fr)
平板端(768px-1024px):
┌──────────┬──────────┐
│ 1 │ 2 │
├──────────┼──────────┤
│ 3 │ 4 │
└──────────┴──────────┘
grid-template-columns: repeat(2, 1fr)
移动端(<768px):
┌──────────────┐
│ 1 │
├──────────────┤
│ 2 │
├──────────────┤
│ 3 │
├──────────────┤
│ 4 │
└──────────────┘
grid-template-columns: 1fr
CSS 代码:
@media (max-width: 1024px) {
.stats {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 768px) {
.stats {
grid-template-columns: 1fr;
}
.stat-value {
font-size: var(--text-2xl);
}
}
```
### 3. 动画数字Stats(带计数效果)
```
数字滚动动画示意:
0 → 15 → 30 → 45 → 45万元
┗━━━━━━━━━━━━━━━━━━━━━━━┛
1.5秒动画
JavaScript实现:
文字内容