|
| 1 | +# CSS Flexbox CheatSheet |
| 2 | + |
| 3 | +### Display Property |
| 4 | + |
| 5 | +```css |
| 6 | +/* Set the container to a flexbox */ |
| 7 | +.container { |
| 8 | + display: flex; |
| 9 | +} |
| 10 | +``` |
| 11 | + |
| 12 | +### Flex Direction Property |
| 13 | + |
| 14 | +```css |
| 15 | +/* Set the main axis direction */ |
| 16 | +.container { |
| 17 | + flex-direction: row | row-reverse | column | column-reverse; |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +### Flex Wrap Property |
| 22 | + |
| 23 | +```css |
| 24 | +/* Allow items to wrap */ |
| 25 | +.container { |
| 26 | + flex-wrap: nowrap | wrap | wrap-reverse; |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### Flex Flow Property |
| 31 | + |
| 32 | +```css |
| 33 | +/* Combine flex-direction and flex-wrap */ |
| 34 | +.container { |
| 35 | + flex-flow: row wrap; |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### Justify Content Property |
| 40 | + |
| 41 | +```css |
| 42 | +/* Align items along the main axis */ |
| 43 | +.container { |
| 44 | + justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly; |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +### Align Items Property |
| 49 | + |
| 50 | +```css |
| 51 | +/* Align items along the cross axis */ |
| 52 | +.container { |
| 53 | + align-items: stretch | flex-start | flex-end | center | baseline; |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Align Content Property |
| 58 | + |
| 59 | +```css |
| 60 | +/* Align wrapped lines along the cross axis */ |
| 61 | +.container { |
| 62 | + align-content: flex-start | flex-end | center | space-between | space-around | stretch; |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Gap Property |
| 67 | + |
| 68 | +```css |
| 69 | +/* Set the gap between flex items */ |
| 70 | +.container { |
| 71 | + gap: 10px; |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Order Property |
| 76 | + |
| 77 | +```css |
| 78 | +/* Change the order of flex items */ |
| 79 | +.item { |
| 80 | + order: 2; |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Flex Grow Property |
| 85 | + |
| 86 | +```css |
| 87 | +/* Allow an item to grow to fill available space */ |
| 88 | +.item { |
| 89 | + flex-grow: 1; |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### Flex Shrink Property |
| 94 | + |
| 95 | +```css |
| 96 | +/* Allow an item to shrink to fit available space */ |
| 97 | +.item { |
| 98 | + flex-shrink: 1; |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +### Flex Basis Property |
| 103 | + |
| 104 | +```css |
| 105 | +/* Set the initial main size of an item */ |
| 106 | +.item { |
| 107 | + flex-basis: auto | 0 | 50%; |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Flex Property |
| 112 | + |
| 113 | +```css |
| 114 | +.item { |
| 115 | + flex: 3 5 500px; /* shorthand for flex-grow flex-shrink flex-basis */ |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +### Align Self Property |
| 120 | + |
| 121 | +```css |
| 122 | +.item { |
| 123 | + align-self: auto | flex-start | flex-end | center | baseline | stretch; |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Learn More about CSS Flexbox from here: |
| 128 | + |
| 129 | +https://css-tricks.com/snippets/css/a-guide-to-flexbox/ |
0 commit comments