Sikau

CSS · Day 7 · about 30 min

Flexbox

Line things up in a row or column.

Layout in one direction

Navigation bars, button rows, a card's header with a title on the left and an icon on the right — that's one-dimensional layout, and Flexbox makes it easy.

Container and items

  • display: flex — children line up in a row (the main axis).
  • flex-direction: column — stack them vertically instead.
  • gap — space between items. Much easier than margins.
  • justify-content — spread along the main axis: flex-start, center, space-between, flex-end.
  • align-items — align across it: stretch (default), center, flex-start.
  • flex: 1 on an item — let it grow to fill leftover space.

The rest of this lesson

  • Main axis and cross axisexplain
  • Patterns you'll use every dayexplain
  • Where do they go?predict
  • Build a headerfill
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of CSS