CSS Flexbox cheatsheet
These CSS rules go inside a flex container (the element containing the boxes to be aligned).
The flex container can be a block or an inline-block element: display: flex; or display: inline-flex;.
The properties with their possible values are a summary of the most-used:
justify-content: horizontal
flex-startgroup items to left (the start) of containerflex-endgroup items to right of containercentergroup items in the center of a containerspace-betweendistribute items: first/last are left/right others are equally betweenspace-arounddistribute and space items evenly
align-items: and align-self: vertical
flex-startacross topflex-endacross bottomcenterin centerbaselineacross baselinestretchspace items or stretch item to fill
flex-direction: order
rowflow left to rightrow-reverseflow right to leftcolumnstack top to bottomcolumn-reversestack bottom to top
flex-wrap: row wrapping
nowrapdefault valuewrapwrap below at narrower widthswrap-reversereverse rows, keep item order
Example
.my-class {
display: flex;
justify-content: space-around;
align-items: flex-start;
flex-direction: column;
}
References
- CSS game: Flexbox Defence
- Dive Into Flexbox (Greg Smith)
- A Complete Guide to Flexbox (Chris Coyier)
- CanIuse: see flexbox browser support (IE11 bugs)