Перейти к основному содержимому
← 🎨 CSS as a design system·Модуль B3 · Урок 2
ЗаданиеBuild a layout with 3 columns of widths 200px, 1fr, 100px. .grid has display: grid, grid-template-columns: 200px 1fr 100px, gap: 8px. Three .cell divs inside.

столбцы/строки сетки-шаблона: явная сетка

75 XP7 min
Теория

Define the track sizes

.grid {
  display: grid;
  grid-template-columns: 200px 1fr 200px;   /* three columns: fixed, fluid, fixed */
  grid-template-rows: 60px auto 40px;        /* three rows: fixed top, content middle, fixed bottom */
}

The browser creates a grid with those tracks. Children flow into cells row-by-row by default.

Unit choices

  • Fixed pixels (200px) — exact width/height.
  • `fr` (fractional) — fraction of REMAINING space after fixed sizes are subtracted.
  • `auto` — sized to fit content.
  • `min-content` / `max-content` — intrinsic content size (covered in lesson 11).
  • `%` — percentage of the grid container.
grid-template-columns: 200px 1fr 1fr;       /* 200px sidebar, two equal-width content cols */
grid-template-columns: 1fr 2fr 1fr;          /* middle column is 2x as wide */
grid-template-columns: auto 1fr;             /* "label column" + "content column" */

Implicit rows

If you don't set grid-template-rows, the browser creates rows AS NEEDED to hold the children. Each implicit row is sized by its content unless you set grid-auto-rows:

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 100px;       /* every implicit row is 100px tall */
}

When to use template-rows

Mostly when you have a FIXED page layout: topbar 60px + main fluid + footer 40px. Defining all rows ensures the layout never shifts as content changes.

🔒

Зарегистрируйся чтобы кодить

Теория открыта всем. Интерактивный редактор, живой превью и проверка открываются с 7-дневным бесплатным trial — нужна карта, отмена в любое время.

Регистрация — бесплатный trial →

Первые 10 уроков в каждом треке — бесплатные. Карта не нужна.

← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.