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.


    Wrap Elements Inside of a Flexed Container with `flex-wrap`

    Chris AchardChris Achard

    To set the wrap settings of elements inside of a container, we can set the flex-wrap css attribute. The most common values are: nowrap, wrap, or wrap-reverse



    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




    Instructor: 0:00 We have our three boxes that are flexed all the way across the screen, but what if our container had a width to it? We could set a width to 150 pixels. Now it smooshes the boxes so that they fit within the container.

    0:14 To get around that, we can set the flex-wrap style. The default is nowrap. That gets us exactly what we have here. It tries not to wrap things and instead smooshes them to fit. We could set that to wrap. Now it wraps them so that they come one after another.

    0:32 This is a little hard to see with the sizes we have. Let's make a few more red boxes here. Now you can see it's wrapped them instead of just putting them in one row or trying to smoosh them.

    0:43 Remember the space between them is controlled by this justify-content. We could, for example, say flex-end for justify-content and take everything to the end here, and it still wraps normally.

    0:55 There's one more wrap we might use, which is wrap-reverse. Now we'll reverse the order of everything in the container, which is kind of a neat idea. It starts at the bottom, and then wraps upwards.