11

I kept getting card grids where the CTA button floated at a different height on every card because each card is its own grid. The naive prompt ("responsive card grid with title, body, button") always gave me flex cards that only align by accident.

The fix was making the model use subgrid so the title/body/footer rows are shared across the whole track, plus banning the height hacks it loves to reach for. Now the footers align even when titles wrap to two lines.

Anyone found a cleaner fallback for browsers without subgrid than duplicating the layout in a @supports block?

THE PROMPT
Build a single-file responsive card grid in plain HTML + CSS. Hard requirements:
- Outer grid: `repeat(auto-fill, minmax(18rem, 1fr))`, gap from an 8px spacing scale only (4, 8, 12, 16, 24, 32px).
- Each card is a grid item that itself uses `grid-template-rows: subgrid` spanning 3 rows (media, content, footer) so titles, body, and the footer button align across ALL cards in a row.
- Do NOT use fixed heights, `min-height` hacks, JS measurement, or `margin-top: auto` inside flex to fake alignment.
- Provide a `@supports not (grid-template-rows: subgrid)` fallback that degrades to per-card flex, clearly commented.
- Focus-visible ring on the card's link, 2px offset, using `outline`, never removing outline without a replacement.
Output the full HTML file. Before the code, list which rows are shared by the subgrid and why.
The focus-visible-with-offset line is the part people forget. Alignment is nice but a card grid you can't tab through is still broken.frontend_fern 1 month ago
add a comment

2 Answers

7

Good instinct forcing subgrid on the rows. One thing that made mine bulletproof: tell it to put align-content: start on the card so the shared rows don't stretch weirdly when one card has less content. Also ask for gap on the subgrid to inherit from the parent rather than redeclaring, otherwise you get double gaps.

THE PROMPT
Amend: card uses `display: grid; grid-template-rows: subgrid; grid-row: span 3; align-content: start;` and must NOT redeclare row-gap (let it inherit from the parent track).
2

For the fallback I stopped duplicating the layout. I ask for a single set of rules and only override the three-row structure inside the @supports not(...) block. Keeps the file ~40% smaller and the two paths can't drift apart when you tweak spacing later.

Your Answer