As highlighted in the "Gotcha",
gap-*
utilities are very handy for creating space *between* elements and work well with both Flexbox and Grid layouts.
gap-4
with Flexbox (and
flex-wrap
)
Here,
gap-4
creates a 1rem gutter both horizontally and vertically between items when they wrap to the next line.
This is simpler than trying to manage margins on individual items.
gap-4
with Grid Layout
With CSS Grid,
gap-4
creates a 1rem gutter between grid columns and rows.
This consistency makes
gap-*
a preferred method for spacing in many layout scenarios.
Recap on "Gotcha" and `gap-*`:
While
justify-*
has its place for distributing items along a flex container's main axis (e.g.,
justify-between
for full-width navs),
gap-*
is often the simpler, more direct tool for creating consistent spacing *between* elements in both Flexbox and Grid. Understanding this distinction helps avoid confusion and write cleaner layout code.