Subgrid Nested Alignment Sync
Synchronize nested grid columns with the parent using CSS subgrid for consistent alignment across complex layouts.
Code
.card-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
gap: 0.5rem;
}
.card-header { font-weight: bold; }
.card-body { color: #555; }
.card-footer { font-size: 0.875rem; }What the code does
display: grid owns the layout: tracks are declared on the container, so children fall into place without wrapper markup.
gap spaces grid/flex items without margins on the children.
grid-template-columns declares the column tracks the children flow into.
The rules target .card-grid, .card-body, .card-footer — each selector names the element it restyles, in source order.
Interactive Tools for This Topic
FAQ
- Which elements does this stylesheet target?
- The rules bind to `.card-grid`, `.card-body`, `.card-footer`; when two rules tie in specificity, the one written later in the file wins.
Report a problem with this exampleOpens a pre-filled issue on GitHub.