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 Creating a Three Column Layout with Flexbox

John Yzaguirre
John Yzaguirre
22,025 Points

flex-basis is a little confusing can someone who understands elaborate?

So I was messing around with flex-basis to see what it is doing and I can't really peg down the behavior. I tried using no-wrap instead on the .row class and it positioned all the columns on one line BUT it made the center column the same width as the side columns. So flex-basis is the way to go for sure. But why? How does it do whatever it is doing? Thanks for any help with this.

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Flex basis is a property that sets the initial size of a flex item.

You can use it to set the width or height of a flex item, or every flex item and then distributes the rest of the available space.

flex-basis: 100%;

Check out this useful article on flex basis. https://css-tricks.com/almanac/properties/f/flex-basis/

I know this is not actually what was asked but I tried using the flex-wrap: nowrap at the second media query and it also worked the same as the flex-basis idea, at least in this specific instance.

Robert Szabo
Robert Szabo
7,999 Points

Well I also tried out what you wrote, but it only partially worked that way. Without setting the flex-basis to 0, you cannot apply the flex-grow: 1.4 value. All 3 columns will be the same size.

Flex basis essentially overrides any previously set width/height on an element once it becomes a flex item.