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 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,143 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,701 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!