CSS Subgrid Alignment
Align nested grid items to parent grid using CSS subgrid for consistent column alignment across complex layouts.
Code
.parent {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 1rem;
}
.child {
display: grid;
grid-template-columns: subgrid;
grid-column: span 3;
}CSS Subgrid Alignment
Align nested grid items to parent grid using CSS subgrid for consistent column alignment across complex layouts.
Code
.parent {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 1rem;
}
.child {
display: grid;
grid-template-columns: subgrid;
grid-column: span 3;
}
Explanation
subgrid lets a nested grid inherit the parent’s tracks instead of defining its own, keeping columns aligned across components. Expected behavior: the child spans the parent’s column lines directly. Limitation: subgrid support is recent, and the nested element must declare subgrid on the axis it wants to inherit.
Interactive Tools for This Topic
CSS Grid PlaygroundExperiment with CSS grid layout properties interactively. Define columns, rows, gaps, and areas while watching the grid template update in a live visual preview.Aspect Ratio CalculatorSimplify a width-to-height ratio, show its decimal value, and derive a matching height for a new width.Border Radius PreviewPreview four-corner border-radius values on a live box and copy the generated shorthand border-radius CSS declaration.Box Shadow GeneratorBuild CSS box-shadow values with offset, blur, spread, color, opacity, and inset controls, with a live preview of the result.
Report a problem with this exampleOpens a pre-filled issue on GitHub.