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 Flexbox Properties Smarter Layouts with flex-basis and flex

Quoc Nguyen
Quoc Nguyen
3,957 Points

Differences between flex-grow: 1; and flex: 1;

I tried flex-grow: 1; and the shorthand flex: 1; The result is different for each. Could you please explain why as I expected similar result.

2 Answers

As Guil mentioned in the video, if you use the shorthand flex, the flex-basis property will be set to 0 (zero ), so it won't wrap the items, it will continue to shrink down towards a zero width.

The initial value for flex-basis is actually auto, not 0, so if you don't set the flex-basis and only use flex-grow, that's what the value will be.

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

The flex-grow property specifies how much the item will grow relative to the rest of the flexible items inside the same container. If the element is not a flexible item, the flex-grow property has no effect.

The flex property specifies the length of the item, relative to the rest of the flexible items inside the same container. The flex property is a shorthand for the flex-grow, flex-shrink, and the flex-basis properties. If the element is not a flexible item, the flex property has no effect.