CSS grid-column / grid-row / grid-area
- type
- properties
- applies to
- grid items
- inherits
- no
- common values
- grid-column: 1 / 3; grid-column: span 2; grid-area: header
Where it goes
On the child item, not the parent. Count lines, not cells: a three-column grid has four column lines. For a named layout, put grid-template-areas on the parent and grid-area on each child.
Example
.layout {
display: grid;
grid-template-columns: 240px 1fr;
grid-template-areas:
"header header"
"sidebar main";
}
header { grid-area: header; }
aside { grid-area: sidebar; }
.featured { grid-column: 1 / -1; }Common mistakes
- Counting cells instead of lines. grid-column: 1 / 3 covers two cells, not three. Lines sit between and around the columns.
- Placing some items by hand and leaving holes. Items you do not place flow into the next free cell, which is often not the one you expected. Place everything, or use grid-auto-flow: dense.
- Using grid-area with a name the parent never declared. The item is placed as if the rule were not there. The name must appear in grid-template-areas.