HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModerate

CSS Grid items overflowing container with minmax

Submitted by: @anonymous··
0
Viewed 0 times
CSS gridminmaxoverflowauto-fillresponsive gridmin function
browsermobile

Error Messages

horizontal scrollbar appears on mobile
grid items overflow container

Problem

CSS Grid items overflow their container when using grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)) on narrow screens. The grid doesn't wrap — it creates horizontal scroll.

Solution

The minmax(300px, 1fr) means items will NEVER be smaller than 300px. On screens narrower than 300px + gap + padding, this causes overflow. Fix: use minmax(min(300px, 100%), 1fr) to clamp the minimum to the container width. Alternatively, use a media query to switch to grid-template-columns: 1fr on small screens.

Why

minmax's first argument is a hard minimum. The min() function creates a responsive floor that adapts to available space.

Code Snippets

Responsive grid that never overflows

grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));

Revisions (0)

No revisions yet.