On this page
Modern Layout: Flexbox & Grid
Prev: Box Model & Formatting Contexts | Up: tutorials | Next: Responsive Design & Theming
Rel: Display & Layout, Math & Sizing Functions
Ref: MDN Web Docs — CSS Grid Layout
Tags: #public #web #css #tutorials #layout
Contents
- > When to Use Flexbox vs. Grid
- > Intrinsic Responsive Grid (Zero Media Queries)
- > Aligning Nested Card Rows with `subgrid`
When to Use Flexbox vs. Grid
- Flexbox: Content-first 1D distribution (navbars, button groups, wrapping tags, centering).
- Grid: Layout-first 2D alignment across both rows and columns (page shells, card grids, dashboards).
Intrinsic Responsive Grid (Zero Media Queries)
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
gap: 1.25rem;
}
Aligning Nested Card Rows with subgrid
grid-template-rows: subgrid lets child cards share the parent grid's row tracks so titles, bodies, and footers align across every column:
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
gap: 1rem;
}
.card {
display: grid;
grid-row: span 3;
grid-template-rows: subgrid;
}
Linked from
Related notes
- tuts/css/properties/display_and_layout Linked here; links to this page; shared tags: #css, #layout, #web
- tuts/css/tutorials Linked here; links to this page; shared tags: #css, #tutorials, #web
- tuts/css/tutorials/box_model_and_formatting_contexts Linked here; links to this page; shared tags: #css, #tutorials, #web
- tuts/css/tutorials/responsive_design_and_theming Linked here; links to this page; shared tags: #css, #tutorials, #web
- tuts/css/functions/math_and_sizing_functions Linked here; shared tags: #css, #web
- tuts/css/properties links to this page; shared tags: #css, #web
- tuts/css/properties/layout shared tags: #css, #layout, #web
- tuts/css/properties/layout/align-items shared tags: #css, #layout, #web
- tuts/css/properties/layout/display shared tags: #css, #layout, #web
- tuts/css/properties/layout/flex shared tags: #css, #layout, #web