跳到正文
Skillpedia
网站与界面(前端)75k · #2799

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/css-grid/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

Rule page: https://frontendchecklist.io/rules/css/css-grid

常见问题

什么时候应该用 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2799
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能