Join egghead, unlock knowledge.

Want more egghead?

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

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


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

    Chris AchardChris Achard

    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.



    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




    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.