liveBook · Manning

Subgrid

As explained in Vanilla Web

Subgrid is a CSS Grid feature that lets a nested grid participate in the track sizing and alignment of its parent grid.

A nested CSS Grid normally needs its own track definitions. Subgrid lets it use the track lines of an ancestor instead, so items in different components can align without duplicating track sizes. section 4.2.2

Use `grid-template-columns: subgrid` to share columns or `grid-template-rows: subgrid` to share rows. The parent establishes the tracks; nested grids follow them when those tracks change. section 4.2.2

Align repeated cards

For cards with headers, bodies, and actions that need to line up across the list, define the shared tracks on the parent grid and use subgrid in the nested card layout. A sidebar and main area can likewise share column boundaries. section 4.2.2

Choose Flexbox for one-dimensional alignment, Grid for two-dimensional tracks, and Subgrid when nested layouts need to share those tracks. Subgrid was added in Baseline 2023. section 4.2 section 4.2.2

How Vanilla Web covers it

How deep it goes
Defines shared tracks, names both axis properties, and gives use cases, but stops short of a worked subgrid stylesheet.
Examples
Uses aligned card headers, bodies, and actions plus shared sidebar and main-content boundaries as use cases.
What it assumes
Assumes familiarity with CSS Grid tracks while defining what subgrid adds to a nested grid.
What you can do after
Apply it via `grid-template-columns: subgrid` or `grid-template-rows: subgrid` to align nested layouts with ancestor tracks.
How it connects
Connects Subgrid to CSS Grid, Flexbox, intrinsic sizing, and responsive layout.

Also explained in

Compare how 2 books explain subgrid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.