Nested Grids and Complex Layouts
- CSS Basics
- Selectors & Specificity
- Box Model & Units
- Typography & Text Styling
- Colors & Color Spaces
- Positioning & Stacking Context
- Flexbox
- Grid
- Grid Advanced
- Responsive Design
- Container Queries
- Pseudo-classes & Pseudo-elements
- Modern Selectors
- CSS Custom Properties
- CSS Functions
- Transitions & Animations
- Transforms
- Forms & Input Styling
- CSS Architecture & Methodologies
- Accessibility in CSS
- Performance & Optimization
- View Transitions & Modern APIs
- Cascade Layers & Scope
Grids Inside Grid Items
Any grid item can itself be turned into a grid container, letting a complex design be broken into an outer page-level grid and independent inner grids inside individual sections - each with its own column and row structure.
.page {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.feature-panel {
grid-column: span 2; /* this panel takes up two of the outer columns */
display: grid; /* and becomes its own grid internally */
grid-template-columns: 1fr 1fr;
}Spanning Multiple Rows and Columns
.hero {
grid-column: 1 / 3; /* spans from line 1 to line 3 */
grid-row: 1 / 3;
}
/* or, using the span keyword */
.hero {
grid-column: span 2;
grid-row: span 2;
}Spanning multiple tracks is how a single featured item - a large hero image, a highlighted card - can take up more visual space than its siblings within the same grid.
Combining Named Areas with Nested Grids
A common real pattern is to lay out the page skeleton with grid-template-areas, then give the "main content" area its own internal grid for a card layout - keeping the outer structure simple to read while still allowing rich internal layout.
Knowing When to Stop Nesting
Nested grids are powerful, but each additional layer adds a place where alignment can drift, especially before subgrid support is considered. For most designs, one outer grid plus a small number of independent inner grids is enough - avoid nesting purely for the sake of it.