Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Flexbox Layout Building a Layout with Flexbox Flexbox Columns Challenge

Flexbox Challenge

Here is the challenge:

Set the columns to expand and display on one line when they are 300px or wider. But when the columns are narrower than 300px, the browser will redistribute the space and display them on multiple lines.

I have tried a few things to the point that I am not connecting with the challenge.

style.css
/* Complete the challenge by writing CSS below */

.row {
  display: flex;
}

.column {
  flex-basis: auto;
}
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Flexbox Layout</title>
    <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="page.css">
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="row">   
      <div class="secondary column">
        <h2>Welcome!</h2>
        <p>Everything in this city is worth waiting in line for. Cupcake ipsum dolor sit.</p>
        <p>Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum.</p>
      </div>

      <div class="primary column">
        <h2>How to get here</h2>
        <p><strong>Plane: </strong>Tiramisu caramels gummies chupa chups lollipop muffin. Jujubes chocolate caramels cheesecake brownie lollipop drag&#233;e cheesecake.</p>
        <p><strong>Train: </strong>Pie apple pie pudding I love wafer toffee liquorice sesame snaps lemon drops. Lollipop gummi bears dessert muffin.</p>
        <p><strong>Car: </strong>Jelly cotton candy bonbon jelly-o jelly-o I love. I love sugar plum chocolate cake pie I love pastry liquorice.</p>
      </div>

      <div class="tertiary column">
        <h2>Great food</h2>
        <p>Croissant macaroon pie brownie. Cookie marshmallow liquorice gingerbread.</p>
        <p>Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum.</p>
      </div>
    </div>
  </body>
</html>

1 Answer

Steven Parker
Steven Parker
231,248 Points

:warning: SPOILER ALERT

The phrase "display them on multiple lines" made me think of the flex-wrap property. This allows the items to wrap when there's not room enough on one line.

Then the "narrower than 300px" made me think of setting a min-width for the columns (which would also work), but since I was going to add a flex property anyway to establish expansion and equal spacing, I just set the second parameter to the minimum size:

style.css
.row {
  display: flex;
  flex-wrap: wrap;
}

.column {
  flex: 1 300px;
}

BTW, flex-basis is auto by default.

Thanks Steve:

I had the flex-wrap in there at one point. I had a separate width in the column without thinking about the fact I could do it with the flex property. I was putting things in and taking them out and moving them back and forth so much, I think I fried my brain.

I appreciate the help.