css-grid
它能做什么
这项技能说明如何用 CSS Grid 构建同时需要行和列的布局。适合希望用更少代码实现响应式布局的前端开发者。
适用场景
- ✓当布局需要行和列同时对齐时。
- ✓当 float 或 flex 的变通方案在不同屏幕尺寸下失效时。
- ✓当你想做响应式卡片网格,又不想写很多媒体查询时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/css-grid/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把我的商品列表重做为一个响应式网格,让它随屏幕宽度自动调整。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会设置网格轨道和命名区域,使用 minmax 和 auto-fill 实现响应式列,并在嵌套项目需要与父级对齐时使用 subgrid。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use CSS Grid for two-dimensional layouts
CSS Grid solves layout problems that previously required JavaScript or complex CSS hacks — aligning items across both axes simultaneously, creating named layout areas, and building responsive grids that adapt to content. Using Flexbox for two-dimensional layouts results in workarounds like fixed widths that break responsiveness.
Quick Reference
- Use Grid for two-dimensional layouts (rows AND columns); use Flexbox for one-dimensional
- grid-template-areas provides a visual representation of the layout in your CSS
- minmax() and auto-fill/auto-fit create responsive grids without media queries
- Subgrid allows nested elements to align to the parent grid's tracks
Check
Look for float-based or Flexbox layouts in this CSS that are trying to control both rows and columns — they may be better implemented with CSS Grid.
Fix
Convert this two-dimensional layout to use CSS Grid with appropriate grid-template-columns, grid-template-rows, and grid-template-areas.
Explain
Explain CSS Grid fundamentals: tracks, cells, areas, fr units, minmax, and auto-fill vs auto-fit.
Code Review
Review stylesheets, component styles, and responsive states related to Use CSS Grid for two-dimensional layouts. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
常见问题
什么时候应该用 Grid 而不是 Flexbox?
这项技能说明,需要行和列同时布局时用 Grid,只需单方向排列时用 Flexbox。
什么是 subgrid?
这项技能说明,它让嵌套元素与父网格的轨道对齐。
网格不用媒体查询也能响应式吗?
可以。这项技能说明,结合 auto-fill 或 auto-fit 使用 minmax,就能创建响应式网格。
详情
作者的原始描述
Use when reviewing stylesheets, component styles, and responsive behavior related to Use CSS Grid for two-dimensional layouts. Check the rendered layout across breakpoints and interaction states before proposing a fix.
热度
- GitHub 星标
- 75k
- 排名
- #2799
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。