Lesson 11 of 14 · 10 min

Flexbox

Laying things out side by side used to be hard. Flexbox makes it easy. Set display: flex on a container, and its direct children line up in a row:

.toolbar {
  display: flex;
}

Then control how the children are arranged:

Property What it does Common values
flex-direction row or column row (default), column
justify-content spacing along the row flex-start, center, space-between, space-around
align-items alignment across the row stretch (default), center, flex-start
gap space between items 8px, 1rem
flex-wrap wrap onto new lines nowrap, wrap

These go on the container. On a child, flex: 1 makes it grow to fill spare space.

Centring anything

The classic "how do I centre this?" problem, solved:

.screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
}

Your task

Make the .menu a flex container where:

  • the items are spread across the width with space-between,
  • they are vertically centred,
  • there is a 12px gap between them.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Menu</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <nav class="menu">
    <a href="#" class="logo">Bytepic Eats</a>
    <a href="#">Menu</a>
    <a href="#">Delivery</a>
    <a href="#" class="order">Order now</a>
  </nav>
</body>
</html>

Your page

Discussion

Stuck? Ask here. Be kind, and share hints rather than full answers.

Loading the discussion…