×

css · level 2 · unit 3 · lesson 4

  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

draws the layout in words.

grid-template-areas lets you draw the layout. Each string in quotes is one row, and each word in it names one cell. Repeat a word to stretch that over several cells.

Then give each child grid-area with one of the names, and it drops into place. A . in the drawing marks a cell left empty.

Every row needs the same number of cells, and every area must be a rectangle. Break either rule and the browser skips the whole drawing.

<div class="page">
  <div class="top">Header</div>
  <div class="menu">Menu</div>
  <div class="main">Today's recipe</div>
</div>
.page {
  display: grid;
  grid-template-columns: 120px 1fr;
  grid-template-areas: "head head" "side main";
}
.top {
  grid-area: head;
}
.menu {
  grid-area: side;
}
.main {
  grid-area: main;
}

Press show my page to see it here.

Swap the drawing to "head head" "main side" and the menu jumps to the right.