CSS Grid Cheat Sheet

  大童  |   on Wednesday, October 15, 2025  |  629   |  2 minutes

📋 CSS Grid 一览表(默认值 + 可选值)

1. 容器属性(Grid Container)

属性默认值 / 可选值说明
displayblock → grid / inline-grid定义网格容器
grid-template-columnsnone → 长度 / 百分比 / fr / repeat() / minmax()定义列宽
grid-template-rowsnone → 长度 / 百分比 / fr / repeat() / minmax()定义行高
grid-template-areasnone → 字符串区域命名区域布局
grid-auto-rowsauto → 长度 / minmax()隐式生成行的高度
grid-auto-columnsauto → 长度 / minmax()隐式生成列的宽度
grid-auto-flowrow → row / column / row dense / column dense自动放置方向与填充策略
gap0 → 长度行列间距(简写)
row-gap0 → 长度行间距
column-gap0 → 长度列间距

2. 容器对齐

属性默认值 / 可选值说明
justify-itemsstretch → start / end / center / stretch所有项目水平对齐方式
align-itemsstretch → start / end / center / stretch所有项目垂直对齐方式
place-items— → align justifyalign-items + justify-items 简写
justify-contentstart → start / end / center / space-between / space-around / space-evenly网格整体水平分布
align-contentstart → start / end / center / space-between / space-around / space-evenly网格整体垂直分布
place-content— → align justifyalign-content + justify-content 简写

3. 项目属性(Grid Item)

属性默认值 / 可选值说明
grid-column-startauto → 数字 / 名称 / span n起始列线
grid-column-endauto → 数字 / 名称 / span n结束列线
grid-row-startauto → 数字 / 名称 / span n起始行线
grid-row-endauto → 数字 / 名称 / span n结束行线
grid-column— → start / end列范围(简写)
grid-row— → start / end行范围(简写)
grid-area— → 区域名 / 行列范围指定区域或位置
justify-selfstretch → start / end / center / stretch单元格内水平对齐
align-selfstretch → start / end / center / stretch单元格内垂直对齐
place-self— → align justifyalign-self + justify-self 简写

4. 常用函数

函数说明
repeat(n, value)重复定义轨道
minmax(min, max)定义最小与最大尺寸
auto-fit自动填充并拉伸项目以填满空间
auto-fill自动填充但不强制拉伸

📐 对齐方式速查

  • align-content / justify-content: 作用于整个网格
    • start / end / center / stretch / space-between / space-around / space-evenly
  • align-items / justify-items: 作用于单元格内所有项目
    • start / end / center / stretch
  • align-self / justify-self: 单独控制某个项目
    • start / end / center / stretch

图示1

cssgrid.png cssgrid-1.png cssgrid-2.png cssgrid-3.png cssgrid-4.png cssgrid-5.png

图示2

cssgrid-6.png cssgrid-8.png cssgrid-9.png cssgrid-10.png cssgrid-11.png cssgrid-12.png