×

css · level 2 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

grid-column lets one child cover several columns.

Between and around every track runs a numbered . Three columns have four lines: line 1 down the left edge, line 4 down the right.

grid-column: 1 / 3 places a child from line 1 to line 3, across two columns. says the same without picking lines: cover two columns, starting wherever it lands.

grid-row does the same for rows, and grid-template-rows sets row heights the way grid-template-columns sets widths, like 120px 80px.

<div class="news">
  <div class="story big">Cat elected mayor</div>
  <div class="story">Rain on Tuesday</div>
  <div class="story">Bake sale</div>
  <div class="story">New library</div>
</div>
.news {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.big {
  grid-column: span 2;
}
.story {
  padding: 12px;
  background-color: oldlace;
}

Press show my page to see it here.

Change span 2 to span 3 and the big story takes the whole first row.