grid layout cheatsheet by @alsacreations
display
defining the grid
grid concepts and example
grid line grid track .parent {
display: grid;
grid· inline-grid· subgrid
1 1 grid-template-columns: 100px 1fr;
2 2
grid-template-rows: auto 1fr auto;
grid-template-rows
3 3 } none· line name· track size· auto
4 4
.one {
.two {
grid-template-columns
grid-row: 1;
grid-row: 1 / 3;
none· line name· track size· auto
grid-column: 1;
grid-column: 2;
grid cell grid area } }
grid-template-areas
1 1
.three {
.four {
none· string
2 2
grid-row: 2 / 4;
grid-row: 3;
3 3
grid-column: 1;
grid-column: 2;
grid-template shortcut for grid-template-rows|-column
4 4
} } grid shortcut for… everything
align-content
gaps
container alignment
auto placement
specifying size of row and column gutters automatic placement for items that aren't placed
vertical alignment for whole grid
1
.parent { 1 2 3 .parent { start· end· center· stretch· space-around
2
row-gap: 50px; 4 5 6
grid-auto-flow: row; space-between· space-evenly
3 } }
4
7 8
justify-content
horizontal alignment for whole grid
1
.parent { 1 4 7 .parent { start· end· center· stretch· space-around
column-gap: 50px; grid-auto-flow: column;
2
2 5 8 space-between· space-evenly
3
} }
place-content
4 3 6
shortcut for align-content and justify-content
1
.parent { 1 2 4 .parent {
2
gap: 50px 10px; 3 5
grid-auto-flow: dense; align-items
3 } } vertical alignment for items in their cells
6
start· end· center· stretch
4
justify-items
grid-row-start grid-row-end grid-row horizontal alignment for items in their cells
placing items
auto· line name· line number auto· line name· line number shortcut for grid-row-start|end start· end· center· stretch
place-items
grid-column-start grid-column-end grid-column shortcut for align-items and justify-items
auto· line name· line number auto· line name· line number shortcut for grid-column-*
grid-area span N justify-self
item alignment
shortcut for… everything keyword for row or column spanning horizontal alignment for specific item in its cell
start· end· center· stretch
.two {
grid-row-start: 1;
.two {
.two {
.four {
align-self
grid-row-end: 3;
grid-row: 1 / 3;
grid-row: 1 / span 2;
grid-area: 2 / 2 / 3 / 3;
vertical alignment for specific item in its cell
} } } } start· end· center· stretch
1 1 1 1 2
place-self
3
2
3
2
3
2
3 4
shortcut for align-self and justify-self
patterns
.parent {
.parent {
align-content: center; grid-auto-rows:
.parent {
.parent {
justify-content: center;
auto 1fr auto;
grid-template-columns: repeat(2, 100px 1fr);
grid-template-columns: repeat(4, 22%);
} } } justify-content: space-between;
}
header
main
footer
english francophone
resources
• Grid by example: https://gridbyexample.com/ • CSS Grid chez Alsacréations : http://kiwi.gg/gridlayout
• Learn CSS Grid: http://learncssgrid.com/ • 50 nuances de grilles : https://speakerdeck.com/goetter/50-nuances-de-grilles
• CSS Grid free videos: https://cssgrid.io/
• CSS Grid Garden: http://cssgridgarden.com/