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 trialQian Chen
33,579 Pointsflex-grow: 3 doesn't seems to be reflected?
The css of flex-grow
:
.item {
flex-grow: 1;
}
.item-3 {
flex-grow: 3;
}
when show in the browser, it seems the item 3 does not really take up 3 time width as other items take.
Qian Chen
33,579 PointsWhen I remove .item { flex-grow: 1; }, the item 3 stretches and takes up all the room while others have fixed width. It's still not 3x as wide as others.
4 Answers
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsI don't think it's going to be 3x the size, it just means it gets 3x the amount of grow that's available.
Jose Esplana
12,503 PointsHi! Brendan Whiting are you able to find a job after completing your Front-end Dev degree? How long did it took you to finish it?
Thanks!
Iain Simmons
Treehouse Moderator 32,305 PointsThe article flex-grow is weird. Or is it? that Guil linked in the teacher's notes explains this issue quite well.
To sum up what is happening, flex-grow
is calculating the free space on the main axis within the flex container and then distributing it to the items based on their flex-grow
value, adding to their existing widths (or heights if the direction is column/vertical).
So if your browser window is too narrow, then there is very little 'free space' left to distribute, so the difference between .item-3
and the rest isn't so large.
Aaron Coursolle
18,014 PointsMy two-cents:
I'm using Chrome and @Jonathan Grieve's code only works when the browser is at full-screen.
When I gradually scale down, the width of item-1 scales down until it is slightly larger than the rest of the list items. Then items drop down to a new line and then they actually wider than item-1. While item-1 is always wider than the items that share its line, it is never double-width ever again.
Jonathan Grieve
Treehouse Moderator 91,253 PointsI'm not sure if you've managed to fix this by now, but adding this code
/* =================================
Flexbox
==================================== */
.container {
display: flex;
flex-wrap: wrap;
}
.item {
flex-grow: 1;
}
.item-1 {
flex-grow: 3;
}
in flexbox.css of your workspace seems to do the trick. The first item is 3 times as large as any of the other.
Qian Chen
33,579 PointsI don't think the first item is 3 times as large as other items. However, it seems the empty space in the first item is 3 times as large as the empty space of other items. Is it actually talking about the free space in an item, instead of the item itself?
Sehui Park
2,518 PointsSehui Park
2,518 PointsI think 'flex-grow:3' means 3 times than original size. So if you remove .item's flex-grow property and keep .item3 property, it shows 3 times width.