|
| 1 | +# CSS Grid CheatSheet |
| 2 | + |
| 3 | +## ****1. Grid container properties**** |
| 4 | + |
| 5 | +### Display |
| 6 | + |
| 7 | +```css |
| 8 | +/* Sets the element to a grid container. */ |
| 9 | +.container { |
| 10 | + display: grid; |
| 11 | +} |
| 12 | +``` |
| 13 | + |
| 14 | +### Grid Template Columns |
| 15 | + |
| 16 | +```css |
| 17 | +/* Defines the columns of the grid. */ |
| 18 | +.container { |
| 19 | + grid-template-columns: 100px 100px 100px; |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +### Grid Template Rows |
| 24 | + |
| 25 | +```css |
| 26 | +/* Defines the rows of the grid. */ |
| 27 | +.container { |
| 28 | + grid-template-rows: 100px 100px; |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +### Grid Template Areas |
| 33 | + |
| 34 | +```css |
| 35 | +/* Defines the areas of the grid. */ |
| 36 | +.container { |
| 37 | + grid-template-areas: |
| 38 | + "header header" |
| 39 | + "sidebar content" |
| 40 | + "footer footer"; |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### Gap |
| 45 | + |
| 46 | +```css |
| 47 | +/* Specifies the size of the gap between grid items. */ |
| 48 | +.container { |
| 49 | + gap: 10px; |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### Justify Items |
| 54 | + |
| 55 | +```css |
| 56 | +/* Aligns items along the inline (row) axis. */ |
| 57 | +.container { |
| 58 | + justify-items: center; |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Align Items |
| 63 | + |
| 64 | +```css |
| 65 | +/* Aligns items along the block (column) axis. */ |
| 66 | +.container { |
| 67 | + align-items: center; |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Justify Content |
| 72 | + |
| 73 | +```css |
| 74 | +/* Aligns the grid along the inline (row) axis. */ |
| 75 | +.container { |
| 76 | + justify-content: center; |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +### Align Content |
| 81 | + |
| 82 | +```css |
| 83 | +/* Aligns the grid along the block (column) axis. */ |
| 84 | +.container { |
| 85 | + align-content: center; |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## 2. Grid Item Properties |
| 90 | + |
| 91 | +### Grid Column Start |
| 92 | + |
| 93 | +```css |
| 94 | +/* Specifies the start position of a grid item along the inline (row) axis. */ |
| 95 | +.item { |
| 96 | + grid-column-start: 1; |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Grid Column End |
| 101 | + |
| 102 | +```css |
| 103 | +/* Specifies the end position of a grid item along the inline (row) axis. */ |
| 104 | +.item { |
| 105 | + grid-column-end: 3; |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +### Grid Row Start |
| 110 | + |
| 111 | +```css |
| 112 | +/* Specifies the start position of a grid item along the block (column) axis. */ |
| 113 | +.item { |
| 114 | + grid-row-start: 1; |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +### Grid Row End |
| 119 | + |
| 120 | +```css |
| 121 | +/* Specifies the end position of a grid item along the block (column) axis. */ |
| 122 | +.item { |
| 123 | + grid-row-end: 3; |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +### Grid Area |
| 128 | + |
| 129 | +```css |
| 130 | +/* Specifies both the start and end positions of a grid item. */ |
| 131 | +.item { |
| 132 | + grid-area: 1 / 1 / 3 / 3; |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +### Justify Self |
| 137 | + |
| 138 | +```css |
| 139 | +/* Aligns a grid item along the inline (row) axis. */ |
| 140 | +.item { |
| 141 | + justify-self: center; |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +### Align Self |
| 146 | +```css |
| 147 | +/* Aligns a grid item along the block (column) axis. */ |
| 148 | +.item { |
| 149 | + align-self: center; |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +Learn More about CSS Grid from here: |
| 154 | +[![Learn CSS Grid in 35 minutes: The Ultimate Crash Course for Beginners]](https://www.youtube.com/embed/ULp7wPJ-rzQ "Learn CSS Grid in 35 minutes: The Ultimate Crash Course for Beginners") |
0 commit comments