考察点:Grid 二维布局能力与典型实现,以及与 Flex 的分工取舍,CSS 布局段位的高级场景题。
要点(Grid 适合什么):
要点(12 列栅格):
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.col-4 { grid-column: span 4; } /* 占 4/12 */
.col-8 { grid-column: span 8; } /* 占 8/12 */
repeat(12,1fr) 生成 12 等宽列,span N 控制跨列;响应式可用容器宽度切换 span 或 auto-fit/minmax。
要点(左固定右自适应两栏):
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
240px 1fr 表示第一列固定 240px、第二列吃掉剩余空间(1fr),比 Flex 写法更直观且无 margin 计算。
要点(Grid vs Flex 取舍):
题目与答案就在本页;收藏、批注和错题重练在应用内