auto-fill vs auto-fit: One CSS Word That Breaks Your Responsive Grid
A widely shared CSS one-liner using repeat() with minmax() creates responsive card grids without media queries, but a subtle keyword choice can cause layout issues when fewer items are displayed. The difference lies in how auto-fill and auto-fit handle empty grid columns: auto-fill retains invisible placeholder tracks that consume available space, pushing visible cards to the left. auto-fit, by contrast, collapses empty tracks to zero width, allowing real cards to expand and fill the entire row evenly. Both keywords calculate the same number of columns upfront, so the bug only surfaces when item count drops below the maximum columns that fit. Swapping auto-fill for auto-fit in the grid-template-columns declaration is the only change needed to fix the layout for variable-count grids like search results or product listings.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in