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

subgrid

它能做什么

这项技能展示如何使用 CSS subgrid,使嵌套项目与父网格的行或列对齐。适用于卡片布局显得参差不齐的网页制作者。

适用场景

  • ✓当卡片网格中的标题、文字或按钮在各卡片之间对不齐的时候。
  • ✓当有人希望在不使用 JavaScript 的情况下对齐嵌套网格项目的时候。
  • ✓当审查 CSS 网格布局,而子项目应当跟随父网格轨道的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/subgrid/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

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

Rule page: https://frontendchecklist.io/rules/css/subgrid

常见问题

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.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能