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
Published 5 years ago
Updated 3 years ago

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.

egghead
egghead
~ 48 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today