Roadmap › HTML5 & CSS3 — Semantic Markup to Responsive Layouts › Module: Layout and Responsive Design
Lessons in this course (11)

7. CSS Grid — two-dimensional layout

Intermediate★ Must knowLesson 7 of 11
css
.page {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100dvh;
}
header { grid-area: header; }  aside { grid-area: sidebar; }  main { grid-area: main; }  footer { grid-area: footer; }

/* Responsive card grid with no media queries */
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

Flexbox vs Grid: Flexbox lays out along one axis and sizes from the content (toolbars, nav bars, button groups). Grid controls rows and columns together from the container (page layouts, card grids, forms). They combine well: Grid for the page, Flexbox inside components.