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

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

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

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.

egghead
egghead
~ an hour 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