Saltar para o conteúdo principal
← 🎨 CSS as a design system·Módulo B3 · Lição 6
TarefaBuild a dashboard using grid-template-areas. .dashboard: display: grid, grid-template-columns: 200px 1fr, grid-template-rows: 60px 1fr 40px, grid-template-areas: 'header header' 'sidebar main' 'footer footer', min-height: 200px. Children: header.h, aside.s, main.m, footer.f — each assigned via grid-area.

grid-template-areas: regiões nomeadas

100 XP9 min
Teoria

Visual layout as ASCII

The most readable grid syntax in CSS:

.dashboard {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 60px 1fr 40px;
  grid-template-areas:
    "header  header"
    "sidebar main"
    "footer  footer";
  min-height: 100vh;
}
.dashboard > header { grid-area: header; }
.dashboard > .sidebar { grid-area: sidebar; }
.dashboard > .main { grid-area: main; }
.dashboard > footer { grid-area: footer; }

The strings inside grid-template-areas are the layout WIRE-FRAME. Each name marks a region. Then assign each child to a region with grid-area.

Why this is unbeatable for layouts

  • You can SEE the layout in the CSS.
  • Reordering means moving names around — no math.
  • Empty cell? Use . (a period).
  • Same area on multiple lines? It spans.
grid-template-areas:
  "header header header"
  "sidebar main main"
  "sidebar . extras"          /* . = empty cell */
  "footer footer footer";

Responsive: just rewrite the areas

@media (max-width: 700px) {
  .dashboard {
    grid-template-columns: 1fr;        /* stack everything */
    grid-template-areas:
      "header"
      "main"
      "sidebar"
      "footer";
  }
}

The CHILD selectors don't change. You just describe a new wire-frame for the smaller screen.

🔒

Regista-te para começar a programar

A teoria está aberta a todos. O editor, a pré-visualização e o check desbloqueiam-se com um teste gratuito de 7 dias — cartão obrigatório, cancelável a qualquer momento.

Registar — teste grátis →

As primeiras 10 lições de cada trilha são grátis. Sem cartão necessário.

← AnteriorPróxima lição →

Recebe uma dica de Python ou web por dia — por email

Curto, escrito à mão, sem spam. Cancela a subscrição num clique.