Intro
A good video to watch: https://www.youtube.com/watch?v=7kVeCqQCxlk
Grid terminology
- Grid
container
: Element containing a grid, defined by settingdisplay: grid
. - Grid
item
: Element that is a direct descendant of the grid container. - Grid
line
: Grid lines are referenced by number, starting and ending with the outer borders of the grid. Starting from 1 - Grid
cell
- Grid
track
: The space between two or more adjacent grid lines. Row tracks are horizontal, column tracks are vertical. - Grid
area
: Rectangular area between four specified grid lines. Can cover one or more cells. - Grid
gap
: Empty space between grid tracks. Commonly called gutters
1 | <div class = "site"> |
1 | .site { |
To make grid more responsive, we use grid-template-areas
. Applied to grid container. Uses a text-based grid map to apply grid area names to individual cells. Then, use grid-area: [area-name];
to specify what grid area the element is placed within.
1 | .site { |
Neted grids
Grids are not inherited by child elements. Instead we create nested grids.
Browser Support
Use feature queries to test for grid support in the current browser. @supports (displahy: grid) {...}
.
CSS Grid approach:
- Build accessible mobile-first layout without grid.
- Use mobile-first layout as fallback for all browsers.
- Use @supports to detect grid support.
- At the appropriate breakpoint, create layout with grid and grid-areas.
- Explore new layout as viewport widens.
[Appendix]
- Firefox has a great grid detector.
- Rachel Andrew’s Grid by Example
- CSS Tricks
- example