9.3 · Layout

Line up across cards: subgrid

Nested grids share their parent’s tracks, so content lines up across siblings.

A card inside a grid is its own little layout. When one card has a longer title, its text and button sit lower than the others, and nothing lines them up.

grid-template-rows: subgrid lets the card use rows from the parent grid. Every card’s title, text and button then share rows, so the tallest title sets the height for all of them.

Before
/* Fixed heights and hope */
.card h2 { min-height: 3lh; }
.card p { min-height: 5lh; }
Now
.card {
  grid-row: span 3;
  grid-template-rows: subgrid;
}