Grid
.grid
.grid — as many equal columns as fit, and never fewer than one.
Examples
One
Each column is at least --grid-min wide.
Two
How many fit is the grid's own width, not the window's.
Three
Drag the window narrower and they reflow with no breakpoint anywhere.
<div class="grid">
<article class="card"><div class="card-body"><h3 class="card-title">One</h3>
<p>Each column is at least <code class="code-inline">--grid-min</code> wide.</p></div></article>
<article class="card"><div class="card-body"><h3 class="card-title">Two</h3>
<p>How many fit is the grid's own width, not the window's.</p></div></article>
<article class="card"><div class="card-body"><h3 class="card-title">Three</h3>
<p>Drag the window narrower and they reflow with no breakpoint anywhere.</p></div></article>
</div>No column count and no media query: you say how narrow a column may get and the number falls out of the width the grid actually has. The same markup gives three columns on a page and one in a drawer.
<div class="grid grid-tight" style="--grid-min: 8rem">
<span class="badge">Lombardy</span>
<span class="badge">Veneto</span>
<span class="badge">Piedmont</span>
<span class="badge">Liguria</span>
<span class="badge">Tuscany</span>
<span class="badge">Lazio</span>
</div>--grid-min is a floor, not a width: the columns grow past it to fill the row. --grid-gap is the other knob, and grid-tight is the one step down that most grids of small things want.
Tokens 2
Level 2, declared on .grid itself. Set any of them on that selector to restyle this utility without touching the skin.
| Token | Default |
|---|---|
| --grid-gap | var(--rhythm-block, 1.5rem) |
| --grid-min | 20rem |
Variants and states
Variants
.grid-tight
Inside it
.grid-fill
State it reads
None.
Before you ship it
What you have to do 3 requirements
- Set
--grid-minto the narrowest a column may usefully be, not to the width you want. It is a floor, and the columns grow past it: a--grid-minof 20rem in a 44rem column gives two columns of 22, not two of 20 and a gap of 4. - Do not put
stackon it. A margin on a grid child adds to the gap rather than replacing it, so the two rhythms compound. The gap is this primitive's, and--grid-gapis how you change it. - Give it items, not text. Like every grid, it makes each child a grid item; a bare text node between two elements becomes an anonymous item of its own and lands in a column. Wrap running copy in an element, or use
stack.
src/css/utilities/grid.css · npx mostlycss add grid