On this page
  1. Modern Layout: Flexbox & Grid
  2. Contents
  3. When to Use Flexbox vs. Grid
  4. Intrinsic Responsive Grid (Zero Media Queries)
  5. Aligning Nested Card Rows with subgrid

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)

.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