Grid-column
Learn item placement across columns with grid-column.
grid-column: placement across columns
In a grid layout, each item occupies one cell by default. With the grid-column declaration you decide how many columns an element spans. A headline, banner or image can then stretch across several columns.
The value uses column line numbers: grid-column: 1 / 4 places the item from line 1 to line 4; that is three columns.
The span keyword
You can use the span keyword instead of an end line. grid-column: 1 / span 3 means 'start at line 1 and span 3 columns'. grid-column: span 2 leaves the start automatic and only fixes the width.
This form is handy when the column count may change later but the element's span width should stay the same. Magazines and newspapers use it often.
The magazine lead story
On a magazine front page the lead story usually spans 2-3 columns, while side stories stay in a single column. With grid-column: 1 / span 3 you place the lead at the start of the grid and stretch it across three columns.
This is the basic way to create visual weight. The reader's eye lands on wide elements first, so the most important content gets the widest area.
Exercise Stretch the lead across 3 columns
On the magazine grid, place the .hero element starting at column line 1 and spanning 3 columns. Write only the grid-column declaration inside the .hero rule.
Show example solution
.hero {
grid-column: 1 / span 3;
}
Test yourself
-
What does grid-column: 2 / 5 do?
.item { grid-column: 2 / 5; }- Places the item from line 2 to line 5
- Places the item from row 2 to row 5
- Hides columns 2 and 5
- Sets the total column count to 5
Show answer
Places the item from line 2 to line 5 — Correct. Both values are column line numbers; the item starts at line 2 and ends at line 5.
-
Span 3 columns
.hero { grid-column: 1 / ____; }Show answer
.hero { grid-column: 1 / span 3; } -
Match each grid-column value to its meaning
- grid-column: 1 / 3
- From line 1 to line 3
- grid-column: 1 / span 3
- From line 1, span 3
- grid-column: 2 / 4
- From line 2 to line 4
- grid-column: auto
- Automatic placement