subgrid
它能做什么
这项技能展示如何使用 CSS subgrid,使嵌套项目与父网格的行或列对齐。适用于卡片布局显得参差不齐的网页制作者。
适用场景
- ✓当卡片网格中的标题、文字或按钮在各卡片之间对不齐的时候。
- ✓当有人希望在不使用 JavaScript 的情况下对齐嵌套网格项目的时候。
- ✓当审查 CSS 网格布局,而子项目应当跟随父网格轨道的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/subgrid/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的产品卡片看起来参差不齐,标题和按钮对不齐。请帮我只用 CSS 修复布局。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会让子元素使用父网格的行或列。之后浏览器会自动对齐每张卡片中对应的部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use CSS subgrid to align nested grid items to parent tracks
Card grids are one of the most common UI patterns, but aligning content across cards — matching title heights, content areas, and footers — has historically required JavaScript height measurement or CSS hacks. Subgrid solves this at the layout engine level: nested items participate directly in the parent grid's tracks, so alignment is automatic, performant, and CSS-only.
Quick Reference
- subgrid lets a nested grid inherit its parent grid tracks instead of creating new ones
- Solves misaligned card titles, content, and footers across rows of cards
- No JavaScript height matching needed — the browser handles track alignment
- Universal support: Safari 16+, Chrome/Edge 117+, Firefox 71+
Check
Look for card grid layouts in this CSS where card content areas (titles, body text, footers) might not align across cards of different content lengths. These are candidates for subgrid.
Fix
Convert this card grid to use subgrid. Show how to set grid-template-rows on the parent grid, then apply grid-row: span N and grid-template-rows: subgrid on each card to inherit the parent tracks.
Explain
Explain how CSS subgrid works, how it differs from a nested grid, what problem it solves with card alignment, and when to use subgrid on columns versus rows.
Code Review
Review card grid and nested grid layouts in this stylesheet. Flag any layout that uses JavaScript height matching, fixed heights, or display: contents workarounds to achieve cross-card alignment — and show the subgrid equivalent.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
常见问题
subgrid 在所有浏览器中都能用吗?
这项技能指出,Safari 16 及更高版本、Chrome 和 Edge 117 及更高版本、Firefox 71 及更高版本都支持它。
subgrid 比用 JavaScript 匹配高度更好吗?
根据这项技能的说法,是的。浏览器自行处理对齐,不需要脚本去测量和匹配高度。
应该用 subgrid 处理列还是行?
取决于需要对齐的方向。这项技能对两种情况都有说明,方便智能体选择正确的方式。
详情
作者的原始描述
Use when reviewing card grid layouts with misaligned content areas, or any nested grid where child items need to align with sibling cards' corresponding sections without JavaScript intervention.
热度
- GitHub 星标
- 75k
- 排名
- #3040
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。