liveBook · Manning

Flex-wrap

As explained in Web Design Playground, Second Edition

The CSS flex-wrap property specifies whether flex items are forced onto one line or can wrap onto multiple lines.

The CSS flex-wrap property decides whether flex items stay on one line or move onto multiple rows or columns. By default, Flexbox uses nowrap and shrinks items to make them fit. section 12.2

Choose the behavior that fits your container:

  • nowrap keeps all items on one row or column; it is the default. section 12.2
  • wrap moves items onto as many rows or columns as needed. section 12.2
  • wrap-reverse creates multiple lines at the end of the cross axis. section 12.2

Make a row wrap

container { display: flex; flex-direction: row; flex-wrap: wrap; } When the items become too wide for the row, the browser places the extras on additional rows instead of shrinking everything to fit. section 12.2

container {
    display: flex;
    flex-wrap: nowrap|wrap|wrap-reverse;
}

Try nowrap, wrap, and wrap-reverse to see how the container's items move. section 12.2

How Web Design Playground, Second Edition covers it

How deep it goes
Defines three values and contrasts wrapping with item shrinking, but defers detailed multi-line alignment to align-content.
Examples
Uses nowrap, wrap, and wrap-reverse in a flex container, with an interactive comparison and a figure showing their effects.
What it assumes
Assumes a Flexbox container and basic awareness of flex-direction, main-axis direction, and cross-axis direction.
What you can do after
Apply it via CSS to choose whether flex items stay together or form additional rows or columns.
How it connects
Connects flex-wrap with Flexbox, flex-direction, the main axis, the cross axis, and align-content.

Also explained in

Compare how 3 books explain flex-wrap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.