There is more to grids than flexbox, so let's pause here to learn more about grids.
Along with containers(parents) and items(children), grids have cells, tracks and areas.
Cell: one(1) unit
Track: range bordered by two(2) lines
Area: range bordered by four(4) lines
grid specs
Grid Components
Property
Value
grid-template-columns
fr
grid-template-rows
auto
grid-template-areas
repeat
grid-area
minmax
Using grid-templates allows developer to,not only have consistency between sections and pages or their site, but also allowsmore precise placement of items that will function as you want them to do even with a change in viewport size. Additionally, it allows for easier item placement when using order and media queries.
Grid columns and rows can be delineated by
Numbered lines
.
Below are layout examples using all three methods.
When defining a grid it is essential that you define the box size. (asterisk(*) represents "universal" and will apply to all)
Look closely at where the columns and rows layout.
.header {
grid-area: hd;
}
.sidebar {
grid-area: sd;
}
.main {
grid-area: content;
}
.footer {
grid-area: ft;
}
.wrapper {
display: grid;
grid-template-columns: repeat(9, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-template-areas:
"hd hd hd hd hd hd hd hd hd"
"sd sd sd content"
". . . ft ft ft ft ft";
}
NOTE:
"." is used as a placeholder. Instead of the footer spanning the entire width, it only occupies three(3) of the nine(9) columns that we designated in our template.
We covered lengths at the beginning of the section. Columns and rows can use relative or absolute lengths. Above we see that the grid columns are set to an absolute length of 200px and rows set to auto.