Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,863 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
210,863 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.