table
table
width
font-size: 0
table
width
table
table
table
width
/ flex-basis
float
, font-size
, white-space
“hacks”grid
styles,grid-template-columns
grid-template-rows
grid-template-areas
grid-template
grid-auto-columns
grid-auto-rows
grid
gap
justify-content
justify-items
align-content
align-items
grid-column-start
grid-column-end
grid-column
grid-row-start
grid-row-end
grid-row
grid-area
order
align-self
justify-self
fr
min-content
max-content
fit-content()
repeat()
minmax()
auto-fit
auto-fill
span
grid-template-columns
grid-template-rows
grid-template-areas
gap
grid-area
fr
repeat()
minmax()
.site {
display: grid;
grid-template-columns:
1fr minmax(65%, 40em)
minmax(35%, 20em) 1fr;
grid-template-areas:
"header header header header"
" . content sidebar . "
"footer footer footer footer";
gap: 12px 16px;
}
.site__header {
grid-area: header;
}
.site__main {
grid-area: content;
}
.site__aside {
grid-area: sidebar;
}
.site__footer {
grid-area: footer;
}
grid-template-columns
Set the proportions for tracks along the inline axis of the grid container
Value: a series of valid length values
1fr 50em 35em 1fr
30% 150px 30%
grid-template-rows
Set the proportions for tracks along the block axis of the grid container
Value: a series of valid length values
1fr 2fr
50px repeat(10, 100px)
grid-template-areas
.
creates a “blank” areagrid-template-areas
.grid {
grid-template-areas:
"header header header header"
" . body sidebar . "
"footer footer footer footer";
}
grid-template-areas
.grid {
grid-template-areas:
"👱♀️ 👱♀️"
"📄 📶"
"🦶 🦶";
}
grid-template
Assign rows, columns, and areas
.grid {
grid-template:
"header header" auto
"body sidebar" auto
"footer footer" auto /
40em 20em;
}
gap
grid-gap
row-gap column-gap
gap: 20px 30px
fr
One “fraction” of the grid’s free space
Calculated after non-fr
space is used
Based on total number of fr
in the row or column
300px 1fr
1fr 50em 25em 1fr
1fr 2fr 3fr
repeat()
Repeats a certain value a specified number of times
repeat(<count>, <length>)
repeat(12, 1fr)
minmax()
Finds a value between two lengths
minmax(<min>, <max>)
minmax(10px, 1fr)
grid-area
Values:
grid-template-areas
namerow-start / column-start / row-end / column-end
.row {
display: grid;
grid-template:
"title date" auto
"actions status" auto /
1fr max-content;
gap: .5rem;
}
.employee {
display: grid;
grid-template:
"photo header" auto
"photo awards" auto
"bio awards" 1fr /
30% 1fr;
gap: 1rem 3rem;
}
.employee {
display: grid;
grid-template:
"photo header" auto
"bio bio" auto
"awards awards" 1fr /
150px 1fr;
gap: 1rem;
}
.employee {
grid-template:
"photo" auto
"header" 1fr /
1fr;
gap: 1rem;
}
.employee__awards,
.employee__bio {
display: none;
}
.image-grid {
grid-template:
" i1 i1 i2 i3" 1fr
" i1 i1 i4 i3" 1fr
" i6 i7 i4 i5" 1fr
" i6 i8 i8 i9" 1fr /
1fr 1fr 1fr 1fr;
gap: 10px;
}
.image-grid {
grid-template:
"i35 i36 i37 i38 i39 i40 i41" 1fr
"i34 i13 i14 i15 i16 i17 i18" 1fr
"i33 i12 i1 i1 i1 i2 i19" 1fr
"i32 i11 i1 i1 i1 i3 i20" 1fr
"i31 i10 i1 i1 i1 i4 i21" 1fr
"i30 i9 i8 i7 i6 i5 i22" 1fr
"i29 i28 i27 i26 i25 i24 i23" 1fr /
1fr 1fr 1fr 1fr 1fr 1fr 1fr;
gap: 10px;
}
One rectangle
Adjacent cells
Strings, not integers
img
assigned to a grid-area
obeys the grid cell size,
not its intrinsic aspect ratio
Wrap images in a container element
Fixed heights => overflow
Flexible row height values: auto
, min-content
, max-content
Some browsers animate
grid-template-columns
grid-template-rows
gap
Can’t animate elements between areas
Grid controls 2 dimensions
Grid allows more precise sizing
Grid has gap
Fallback layout CSS (if possible)
Autoprefixer can help (if necessary)
No gap
support
jdsteinbach