Let Items Grow and Shrink

The events banner now has room to breathe, and you can move its heading and line along either axis. While the banner was still a row, though, those two items filled it edge to edge and wrapped onto two lines each. Flexbox decided how wide each one ended up, and you didn’t choose it.

Rosa wants the work day page’s sign-up notice laid out like a contact card, with the round photo on the left and the text beside it. In this lesson, you’ll decide how much each item in a row may grow or shrink and fix an item that refuses to shrink at all. Start by putting the notice in a row and seeing what the browser does with it.

Put the Photo Beside the Text

The notice sits in events/work-day.html, below the date. It’s a <div> with two children, the photo and the paragraph:

Language: HTML
<div class="sign-up">
  <div class="sign-up-photo"></div>
  <p>
    Rosa needs to know who's coming. Sign up at
    https://elmstreetgarden.org/signup?event=workday&amp;season=spring2027&amp;shifts=saturdaymorningsninetonoon&amp;from=workdaypage
    by Thursday.
  </p>
</div>

The photo is decoration, so it’s a background instead of an <img>, and it needs no alt text. A <style> element in the page’s <head> sizes it and turns it into a circle:

Language: CSS
.sign-up-photo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: url("../images/work-day.jpg") center / cover;
}

Open the work day page in your browser. The notice stacks in normal flow, with the photo above the text:

The work day page with a round garden photo above Rosa's sign-up paragraph, whose long URL fills a line of its own.
The Sign-Up Notice in Normal Flow

To put the photo and the paragraph side by side, make their parent a flex container. Add this rule at the end of events/layout.css:

Language: CSS
.sign-up {
  display: flex;
  gap: var(--space-m);
}

The page’s column has 752 pixels for content. The photo takes 120 of them and the gap 16, which leaves 616 for the paragraph. Before you save, predict: Does the paragraph narrow to 616 pixels and wrap its text to fit?

The two items sit side by side, but neither one ends up the size you’d expect:

The photo is squashed into a narrow oval beside the paragraph, and the URL's long line runs well past the column's right edge.
A Squashed Photo and a URL That Runs Out of the Column

The photo is now an oval, 85.5 pixels wide and still 120 tall. The paragraph didn’t narrow to 616 pixels. It’s 650.5 pixels wide, and the URL’s long line runs about 100 pixels past the right edge of the column. As always in CSS, the browser reports no error when the layout comes out wrong.

Two flexbox defaults cause this, one for each item.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.