A two-dimensional layout system, controlling layout both in rows and columns.
The container that holds the entire CSS grid. It is the element that has display: grid
or inline-grid
property on it.
.grid-container {
display: grid;
}
Any element that is a direct child of a grid container.
.grid-container {
display: grid;
}
Grid Item 1
Grid Item 2
Grid Item 3
The vertical and horizontal lines that divide the grid and separate the columns and rows.
Their numbering starts with 1 (not 0).
A single unit of a CSS grid.
Rectangular space surrounded by four grid lines.
A grid area can contain any number of grid cells.
The space between two grid lines.
This space can be horizontal or vertical.
A horizontal track of a grid.
A vertical track of a grid.
The space between rows and columns in a grid.
.grid-container {
display: grid;
grid-template-columns:repeat(3, 1fr);
}
Grid Item 1
Grid Item 2
Grid Item 3
grid-template-columns
grid-template-rows
A way to define the number of rows and columns as well as their size.
fr
fr
?
repeat()
do?
repeat(4, 25%)
vs.
repeat(4, 1fr)
with
grid-column-gap: 10px
?
.grid-container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-template-rows: 4fr 1fr 2fr;
}
with dynamic row and column size
.grid-container {
display: grid;
grid-template-columns: minmax(auto, 40%) 1fr 12rem;
grid-template-rows: minmax(75px, auto) minmax(75px, 150px) auto;
}
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
Grid items are positioned using grid lines.
.item-1 {
grid-row: 2/3;
grid-column: 2/3;
}
.item-3 {
grid-row: 3/4;
grid-column: 3/4;
}
Item 1
Item 2
Item 3
grid-row
grid-row-start
grid-row-end
grid-column
grid-column-start
grid-column-end
What is
grid-area
again?
grid-row-start
grid-column-start
grid-row-end
grid-column-end
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-template-areas:
"header header header"
"sidebar content-1 content-1"
"sidebar content-2 content-3"
"footer footer footer";
}
.sidebar {
grid-area: sidebar;
}
…
Go to the code sandbox and fill up the available space with the person tiles. Think of mobile, tablet and desktop widths. Align the previously built person tiles using a CSS grid layout.
Hint: Try if you can make the layout responsive without media queries.