×

css · level 2 · unit 1 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

lets a full row spill onto a new line.

A flex row never breaks by itself. On a narrow phone, the children squeeze and squash to stay on one line, even when that makes them hard to read.

flex-wrap: wrap fixes that. When the next child does not fit, it moves down and starts a new line, like words in a paragraph.

Now gap can take two values: the between lines first, then the between neighbours. gap: 12px 8px means 12px between lines and 8px across.

<div class="tags">
  <span class="tag">Cats</span>
  <span class="tag">Dogs</span>
  <span class="tag">Rabbits</span>
  <span class="tag">Hamsters</span>
  <span class="tag">Parrots</span>
  <span class="tag">Goldfish</span>
</div>
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 8px;
}
.tag {
  width: 120px;
  padding: 8px;
  background-color: lavender;
}

Press show my page to see it here.

On a narrow screen the tags wrap. Remove flex-wrap: wrap; and they squeeze onto one line instead.