root@coding-prodigies:~# โ–Š
// lesson 3 of 12 ยท 22 min

Box model, Flexbox, and Grid

โš‘ Report an issue with this lesson
* { box-sizing: border-box; }

.nav { display: flex; justify-content: space-between; gap: 16px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

Flexbox for one-dimensional layouts (a row of nav links, a button group). Grid for two-dimensional layouts (a card gallery, a page skeleton). Most real pages use both together, nested inside each other.

Try it yourself

Exercise: Turn .cards into a 3-column grid using display: grid.
html
Live preview
// that was the last free lesson

9 more lessons โ€” including Capstone project: a multi-page site โ€” plus a certificate are waiting.

Unlock the full course โ€” $149.99