Перейти до основного вмісту
← 🎨 CSS as a design system·Модуль B6 · Урок 8
ЗавданняBuild a 6-card grid that flows without media queries. .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }. Six .card divs each with padding 16px, background #eef, border-radius 8px.

Сітка з автоматичним підбором: адаптивний ряд карток без точок розриву

100 XP7 min
Теорія

You saw this in B3 — now apply it as the default responsive layout

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

That's a fully responsive card grid. NO media queries:

  • Desktop (1200px): 5 cards × 240px.
  • Tablet (800px): 3 cards × 270px.
  • Phone (375px): 1 card × 375px.

The grid reflows automatically. The minimum (240px) prevents cards from squishing too narrow; the 1fr lets them stretch to fill.

When to use auto-fit vs auto-fill

  • auto-fit — empty space collapses; tracks GROW to fill.
  • auto-fill — empty space stays; tracks keep their minmax width.

Most card grids want auto-fit (no awkward empty columns on wide screens).

When breakpoints are still useful

For DRAMATIC layout shifts (sidebar disappears entirely on mobile, hamburger menu appears), media queries make sense:

.layout { display: grid; grid-template-columns: 240px 1fr; }
@media (max-width: 720px) { .layout { grid-template-columns: 1fr; } }

For PROPORTIONAL adjustments (card sizes, padding, font), use clamp + auto-fit.

Rule of thumb

If you can describe the change as "scale this number up", use clamp. If "rearrange these elements", use breakpoint. Most projects need 1-2 breakpoints total.

🔒

Зареєструйся щоб кодувати

Теорія відкрита всім. Інтерактивний редактор, живий перегляд і перевірка відкриваються з 7-денним безкоштовним trial — потрібна картка, скасування у будь-який час.

Реєстрація — безкоштовний trial →

Перші 10 уроків у кожному треку — безкоштовні. Картка не потрібна.

← НазадНаступний урок →

Отримуй одну пораду з Python чи вебу — щодня поштою

Коротко, без води, без спаму. Відписка — в один клік.