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 Sass Basics Write Smart and Efficient CSS with Sass Create a Function for Flexbox Layout

Alyssa Nienstedt
Alyssa Nienstedt
13,114 Points

Flex:1? clarification

I thought I understood flexbox, but I seem to be missing something. In setting flex:1 shouldn't each of the .card elements "grow" to take up the entire width of the .main-content container (thereby stacking them)? Why would they be positioned next to one another?

2 Answers

Karan Nahar
Karan Nahar
16,157 Points

Hi! Alyssa. When you set flex: 1 your card elements will take equal widths in the container horizontally . If you want your card items to be stacked on top of each other vertically and take up the full width give the flex container a flex-direction: column.

Alyssa Nienstedt
Alyssa Nienstedt
13,114 Points

Hi Karan, Thanks for you response. I saw the flex-direction was set to column for .card and must have similarly attributed that rule to the container which threw me off. Don't try to code at midnight when you're tired haha Thanks again.

David Kanwisher
David Kanwisher
9,751 Points

I scratched my head over the same thing for longer than I care to admit. Thanks for asking such a great question, and thanks for the great answer Karan!