Components
Card grid
Responsive grids of cards, pairs and stat tiles.
Responsive grids of Cards: as many columns as fit, a two-up pair, or packed stat tiles.
Live example
The real classes from /site/chitransit.css in frames at phone, tablet and desktop widths, in the docs theme. The contract below shows each width in light and dark.
Code
<div class="ct-card-grid">
<section class="ct-card">…</section>
<section class="ct-card">…</section>
</div>
<div class="ct-card-grid ct-card-grid--pair">…</div>
<div class="ct-card-grid ct-card-grid--tiles">…</div>
Responsive behavior
| Viewport | Layout |
|---|---|
| > 760 wide | Columns at least 300 wide (size.cardGridMinimum), 16 apart; pairs two up; tiles at least 130 wide. |
| ≤ 760 wide | Cards in one column. |
| ≤ 600 wide | Pairs in one column. Tiles never collapse. |
Tokens
From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix.
| Custom property | Value | Alias | Resolves to |
|---|---|---|---|
--ct-card-grid-gap | var(--space-16) | {space.s16} | 16 pt |
--ct-card-grid-gap-pair | var(--space-12) | {space.s12} | 12 pt |
--ct-card-grid-gap-tiles | var(--space-8) | {space.s8} | 8 pt |
--ct-card-grid-min | var(--size-card-grid-minimum) | {size.cardGridMinimum} | 300 pt |
--ct-card-grid-min-tiles | var(--size-tile-grid-minimum) | {size.tileGridMinimum} | 130 pt |
Variants
The default fits as many columns at least 300 wide as the width allows. --pair is two equal columns; --tiles packs small stat tiles and never collapses. Nothing else exists.
- Cards of one kind, any number: the default.
- Two cards that belong side by side:
--pair. - Small stat tiles:
--tiles.
<!-- Do -->
<div class="ct-card-grid ct-card-grid--pair">
<section class="ct-card">…</section>
<section class="ct-card">…</section>
</div>
<!-- Don't: a hand-set column count -->
<div class="ct-card-grid" style="grid-template-columns:repeat(3,1fr)">…</div>
Usage
Do
- Keep cards in a grid the same kind and roughly the same height.
Don't
- Don't rely on the grid for order; source order is reading order.
Accessibility
- Give each card a heading; the grid itself is not announced.
Contract
Contract: components/card-grid.yaml. States are drawn live by transit.js.
Loading the contract…