https://huijing.github.io/slides/grid-workshop/files/grid-workshop-files.zip
Images and explanations by Lin Clark
Images and explanations by Lin Clark
Images and explanations by Lin Clark
Images and explanations by Lin Clark
Images and explanations by Lin Clark
Images and explanations by Lin Clark
Based on the container-child relationship
“Grid works from the container in, other layout methods start with the item”
—Rachel Andrew
inline-block
Item A
Item B
Item C
Item D
Item E
Item F
float
Item A
Item B
Item C
Item D
Item E
Item F
flex
Item A
Item B
Item C
Item D
Item E
Item F
“Grid is the only layout technique that establishes a relationship between rows and columns of grid items.”
<div class="grid1">
<div class="grid1__item">
<p>Item A</p>
</div>
<div class="grid1__item">
<p>Item B</p>
</div>
<div class="grid1__item">
<p>Item C</p>
</div>
<div class="grid1__item">
<p>Item D</p>
</div>
<div class="grid1__item">
<p>Item E</p>
</div>
<div class="grid1__item">
<p>Item F</p>
</div>
</div>
Item A
Item B
Item C
Item D
Item E
Item F
Item A
Item B
Item C
Item D
Item E
Item F
Item A
Item B
Item C
fr
unitRepresents a fraction of the free space in the grid container.
Item A
Item B
Item C
.container {
display: grid;
grid-template-columns: repeat(3, 3fr 2fr);
}
minmax()
functionDefines a size range for columns or rows in the grid.
Item A
Item B
Item C
repeat()
functionTo specify a large number of columns or rows that follow a similar pattern
Item
Item
Item
Item
Item
Item
Item
Item
auto-fill
versus auto-fit
A
B
C
D
E
F
.container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(10em, 1fr));
}
grid-column
and grid-row
🍏
🍊
🥥
🥑
🍇
🍌
grid-area
Item A
Item B
Item C
Property | Axis | Aligns | Applies to |
---|---|---|---|
justify-content |
main/inline | content within element |
block containers, flex containers and grid containers |
align-content |
cross/block | ||
justify-self |
inline | element within parent |
block-level boxes, absolutely-positioned boxes and grid items |
align-self |
cross/block | absolutely-positioned boxes, flex items and grid items |
|
justify-items |
inline | items inside box |
block containers and grid containers |
align-items |
cross/block | flex-containers and grid-containers |
Source: CSS Box Alignment Module Level 3
justify/align-content
content-distribution properties
Values | justify-content |
align-content |
---|---|---|
center |
||
start |
||
end |
||
space-around |
||
space-between |
||
space-evenly |
justify/align-self
self-alignment properties
justify/align-items
defaults for justify/align-self
Simple responsive dashboard
Artist profile page
See the Pen The Critical Request header by Chen Hui Jing (@huijing) on CodePen.