Sikau

CSS · Day 8 · about 25 min

Flexbox: wrapping and sizing

flex-wrap, flex-grow and centring anything.

When the row runs out of room

On a phone, five tags won't fit in one line. Wrapping lets items flow onto new lines, and flex sizing decides how items grow and shrink. Plus: the famous two-line trick for centring anything.

Wrap, grow, shrink, basis

  • flex: 1 1 200px = grow, shrink, and a starting size (flex-basis) of 200px.
  • flex: 1 — all items share space equally.
  • flex-shrink: 0 — never squash this item (handy for icons).
  • Centring: display: flex; justify-content: center; align-items: center; on the parent.

The rest of this lesson

  • How flex sizing really worksexplain
  • Wrapping layoutsexplain
  • What happens on a narrow screen?predict
  • Flex shorthandsmatch
  • 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