๐ŸŽ

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 06 : 01 : 22
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
1ร—
Become a member
to unlock all features
Autoplay

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

    Chris AchardChris Achard
    flexboxFlexbox
    cssCSS

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Chris Achard: 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.

    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.

    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.

    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.