CSS Basics · Lesson 8 of 11

Flexbox: Alignment and Wrapping

justify-content positions items along the row. Three more properties finish the picture.

align-items

align-items positions items across the row, which for a normal row means up and down:

.bar {
  display: flex;
  align-items: center;
}

Use it when items in a row have different heights, such as a picture next to a line of text. Values include flex-start (top), center and flex-end (bottom).

Putting both together centers something in both directions, a job that was famously awkward before flexbox:

.box {
  display: flex;
  justify-content: center;
  align-items: center;
}

flex-wrap

By default a flex container squeezes all of its items onto one row. With flex-wrap: wrap, items that do not fit move down to a new row:

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

flex: 1

This one goes on an item, not the container. flex: 1 tells the item to grow and take up the leftover space. If several items have it, they share the space equally.

Your Task

  1. Make .profile a flex container with a gap of 16px, and center its items vertically with align-items.
  2. Give .info the declaration flex: 1 so it takes all the space left of the button.
  3. Make .tags a flex container that wraps, with a gap of 8px.
  • .profile is a flex container with a 16px gap
  • The items in .profile are centered vertically
  • .info grows to fill the leftover space
  • .tags is a flex container that wraps, with an 8px gap