Przejdź do treści głównej
← 🎨 CSS as a design system·Moduł B3 · Lekcja 4
ZadanieBuild a 6-column equal-width grid using repeat. .grid display: grid, grid-template-columns: repeat(6, 1fr), gap: 8px. Six .item cells, each padding 12px, background #eef.

powtarzanie(): czysty skrót dla powtarzających się ścieżek

75 XP6 min
Teoria

Stop writing 1fr ten times

grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr;   /* 😬 */
grid-template-columns: repeat(10, 1fr);                          /* same, sane */

Patterns

grid-template-columns: repeat(3, 1fr);              /* 3 equal columns */
grid-template-columns: repeat(4, 200px);            /* 4 fixed 200px columns */
grid-template-columns: repeat(2, 1fr 2fr);          /* alternating: 1fr 2fr 1fr 2fr */
grid-template-columns: 200px repeat(3, 1fr) 200px;  /* sidebar + 3 equal + sidebar */

The second arg can be a list of track sizes — repeat(2, 1fr 2fr) expands to 1fr 2fr 1fr 2fr (the pair repeated twice).

Implicit row repeat

grid-auto-rows: 100px defines an implicit row height for every row beyond the explicit ones:

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 80px;
}

Every row in this grid is 80px tall regardless of how many rows the children create.

Up next: auto-fit + minmax

repeat() has a magic feature — auto-fit — that makes responsive grids without media queries. We'll see it in lesson 8.

🔒

Zarejestruj się, aby zacząć kodować

Teoria jest dostępna dla każdego. Edytor, podgląd na żywo i check odblokowują się z 7-dniowym darmowym okresem próbnym — wymagana karta, anuluj w dowolnym momencie.

Zarejestruj się — darmowy okres próbny →

Pierwsze 10 lekcji w każdej ścieżce jest darmowych. Karta nie jest wymagana.

← PoprzedniaNastępna lekcja →

Codziennie jedna wskazówka Python lub web — na maila

Krótko, ręcznie pisane, bez spamu. Wypisanie w jedno kliknięcie.