CSS chapters

Chapter 10 of 17

Flexbox for one-dimensional layout

Try this in our CSS Compiler →

The idea

Flexbox arranges direct children along a main axis. justify-content aligns on that axis; align-items works on the cross axis. gap spaces items without margins on the outer edges. Enable wrapping when content may exceed the available width.

Worked example

nav ul { display: flex; flex-wrap: wrap; gap: 12px; padding: 0; list-style: none; }
nav li { padding: 8px; }

What to check

Only direct children of the flex container become flex items. With flex-direction: column, the meaning of horizontal versus vertical alignment changes.

Practice task

Create three items of different text lengths. Switch the main axis and explain how each alignment property now behaves.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on