Flexbox Tutorial
See the freeCodeCamp article for a follow along: Learn basic Flexbox in just 10 minutes
Level 1 — Basic
1) Creating a flex container
{ display: flex; }
Div One
Div Two
Div Three
2) Put flex items in a single column
{ flex-direction: column; }
Div One
Div Two
Div Three
{ flex-direction: column-reverse; }
Div One
Div Two
Div Three
Level 2 — Beginner
1) Align flex items to the right
{ justify-content: flex-end; }
Div One
Div Two
Div Three
2) Center-align flex items
{ justify-content: center;}
Div One
Div Two
Div Three
3) Spread out flex items
{ justify-content: space-evenly; }
Div One
Div Two
Div Three
{ justify-content: space-between; }
Div One
Div Two
Div Three
justify-content: space-around;
Div One
Div Two
Div Three
4) Align flex items in a second direction
{ justify-content: center; align-items: center; }
Div One
Div Two
Div Three
5) Align a particular flex item
.flex-container10 {justify-content: center; align-items: center;}
.three10 {align-items: flex-end};
Div One
Div Two
Div Three
Level 3 — Intermediate
1) Allow flex items to wrap into other rows/columns
{ flex-wrap: wrap; }
Div One
Div Two
Div Three
2) Reverse wrapping
{ flex-wrap: wrap-reverse; }
Div One
Div Two
Div Three
3) Justify position of lines of elements
{ flex-wrap: wrap; align-content: flex-start; }
Div One
Div Two
Div Three
Level 4 — Advanced
1) Expand elements
.flex-item:nth-of-type(1){ flex-grow: 1;}
.flex-item:nth-of-type(2) { flex-grow: 2;}
Div One
Div Two
Div Three
2) Shrink elements
.flex-item:nth-of-type(1){ flex-shrink: 1;}
.flex-item:nth-of-type(2) { flex-shrink: 2;}
Div One
Div Two
Div Three
3) Set the size of elements
.flex-item:nth-of-type(1){ flex-basis: 200px;}
.flex-item:nth-of-type(2) { flex-basis: 10%;}
Div One
Div Two
Div Three
4) Put flex-grow, flex-shrink, and flex-basis together
.flex-item:nth-of-type(1) { flex: 1 0 100px; }
.flex-item:nth-of-type(2) { flex: 2 0 10%; }
Div One
Div Two
Div Three