Module 15: Page Layouts

Lesson 2 of 5 · 15–25 minutes

Flexbox basics

🏠The everyday picture

Books on a shelf. You decide whether they lean left, centre or right, how much space goes between them, and whether they stand in a row or are stacked in a pile.

📘What it really is

nav ul {
  display: flex;
  gap: 1rem;
}

Now the list items sit in a row with 1rem between them.

🖱️Try it

Make your nav list a row with display: flex, remove the bullets (list-style: none; padding: 0;), and add a gap. Then make your <header> a flex container with justify-content: space-between and align-items: center, with your name on the left and the nav on the right.

✅Quick check

You want a logo on the far left and a menu on the far right of the header. Which Flexbox setting?

Show the answer

justify-content: space-between on the header.

How do you centre something both ways with Flexbox?

Show the answer

On its container: display: flex; justify-content: center; align-items: center;.

← PreviousThe box model
ProLearners Assist