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 Building a Navigation Bar with Flexbox

Y B
Y B
14,136 Points

Flexbox, flex shorthand doesn't give same results as flex-grow

In the CSS flexbox course, video where we are building the columns. The solution in the video to make even sized 2 columns is to use

.col { flex: 1} Which from the course is shorthand for .col {flex-grow: 1} However if I use the second method then this doesn't work and my columns are still adjusted based on content. I have to use flex-basis to correct this with: .col { flex-basis: 50%}

Does the flex shorthand mean something different than flex-grow when used with just a single entry?

2 Answers

Steven Parker
Steven Parker
231,248 Points

You're exactly right.

The flex shorthand always sets 3 properties even if you don't provide them all. The properties that are set, in order, are flex-grow, flex-shrink, and flex-basis.

When flex is used, but the flex-basis is not explicitly specified, it gets set to 0.

Y B
Y B
14,136 Points

Ah thanks, not sure what flex-basis means when set to 0 though?

Steven Parker
Steven Parker
231,248 Points

I think it essentially means "no minimum", but the important thing is that it's different from the default of "auto" which is what you get if you haven't used flex.

Y B
Y B
14,136 Points

I think now I get it - basis is the basis used to determine how items grow or shrink relative to the size set with basis. If not set, then the default of auto, sets grow, shrink to a basis based on the content of each item.