Web DesignStyling & layoutLesson 5 / 69

Flexbox layouts

Exercise35 min

Flexbox layouts

Flexbox lays children in a row or a column and distributes space between them:

.nav {
  display: flex;
  justify-content: space-between; /* along the main axis */
  align-items: center;            /* along the cross axis */
  gap: 12px;
}

The mental model: pick a main axis (row or column), then two dials — justify-content moves things along the axis, align-items moves them across it. gap spaces children without margin hacks.

Flexbox is your default for toolbars, cards in a row, and any "put these next to each other" job.

Exercise

Build a page header with flexbox: a logo on the left, three links on the right. Then make it a column and watch which axis you now justify.

Practice in the diagram lab

This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.

Open the diagram lab