празнина: чисто разстояние без хакове за маржове
The right way to space flex/grid items
.row {
display: flex;
gap: 16px; /* equal spacing between siblings */
}
.row {
gap: 16px 8px; /* row-gap col-gap (when wrapping) */
}gap puts space BETWEEN siblings — not before the first, not after the last. Compare:
/* Old way — leading/trailing margin needs cleanup */
.row > * { margin-right: 16px; }
.row > *:last-child { margin-right: 0; } /* ugh */
/* New way */
.row { gap: 16px; } /* done */Works in grid, flex and multi-column (not plain block)
gap started life in CSS Grid (2017), spread to Flexbox (2021), and also applies to multi-column layouts (column-gap). It does not apply to plain block containers — a <div> with normal flow ignores gap; make it display: flex or display: grid first. Either way, the days of "margin-right except last child" hacks are over.
Two values
gap: 16px 24px is row-gap col-gap. When you wrap, vertical gaps between rows can be different from horizontal gaps between items.
.cards {
display: flex;
flex-wrap: wrap;
gap: 20px 12px; /* 20px between rows, 12px between cards in a row */
}The mental shift
If you find yourself writing margin to space SIBLINGS, switch to gap on the parent. Use margin only for "this element's spacing from the world" (parent padding, neighboring sections).
Регистрирай се за да започнеш да кодираш
Теорията е отворена за всички. Редакторът, живият преглед и проверката се отключват с 7-дневен безплатен пробен период — нужна е карта.
Регистрация — безплатен пробен период →Първите 10 урока във всеки път са безплатни. Без карта.