Loading lessons...
Flex Direction & Wrap
Flex Direction & Wrap
The flexbox system controls the main axis, wrapping, alignment, ordering, and growing/shrinking of items.
Display flex
flex sets display: flex (or inline-flex):
<div class="flex">...</div>
Flex direction
Controls whether items lay out in a row or column:
| Class | CSS |
|---|---|
flex-row | row (default) |
flex-row-reverse | row-reverse |
flex-col | column |
flex-col-reverse | column-reverse |
flex-row makes items sit side by side (main axis = horizontal); flex-col stacks them vertically (main axis = vertical).
<div class="flex flex-col">
<span>One</span>
<span>Two</span>
</div>
Flex wrap
| Class | CSS |
|---|---|
flex-wrap | wrap onto multiple lines |
flex-wrap-reverse | wrap in reverse |
flex-nowrap | single line (default) |
<div class="flex flex-wrap">
<!-- items will wrap instead of overflowing -->
</div>
Main axis vs cross axis
justify-*aligns along the main axis.items-andcontent-align along the cross axis.- In
flex-row, the main axis is horizontal; inflex-col, vertical.
TL;DR
flexto enable flexbox.flex-row/flex-colchoose the main axis.flex-wraplets items wrap onto new lines.- Justify controls main axis; items/content control cross axis.