Proportionally Grow a Flexed Element by Setting `flex-grow` or `flex` Styles

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet

To stretch individual elements to fit the given space, we can set the flex-grow or flex attributes to any integer. Other surrounding elements will grow proportionally to their flex-grow or flex attributes.

Chris Achard: [00:00] Here we have a red, green, and blue box inside of a container. They're all set to have a min-width of 50 and a min-height of 50.

[00:09] Let's say we wanted this green one to grow to fill the size between the red and the blue. We can set that with the flex-grow property. Let's just set it to one. It can be any integer. Because the other two aren't set, if we refresh now, it will grow to one and the other two will remain at their min-width.

[00:27] We can set the others as well. Let's say we set this red one to be a flex-grow of two. It will try to be about two times the size of this green one. We can do the same for the blue one. Let's say we set flex-grow here to 10. It will try to be 10 times the size, though it's constrained by how wide it can get.

[00:49] We can also do this by setting flex. Flex and flex-grow will accomplish almost the same thing. You can see that it tries to push it even further. Flex will get you closer than flex-grow.