> All in One 586: You want minmax(10px, 1fr) not 1fr

Ads

Friday, January 22, 2021

You want minmax(10px, 1fr) not 1fr

There are a lot of grids on the web like this:

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

My message is that what they really should be is:

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(10px, 1fr));
}

Why? In the former, the minimum width of the grid column is min-content, which can be awkwardly wider than you want it to be (see: grid blowouts). In the latter, you’ve reduced the minimum to 10px (not zero, so it doesn’t disappear on you and lead to more confusion).

While it’s slightly unfortunate this is necessary, doing it leads to more predictable behavior and prevents headaches.

That’s it. That’s my whole message.

(Blog post format kiped from Kilian’s “You want overflow: auto, not overflow: scroll” which is also true.)


The post You want minmax(10px, 1fr) not 1fr appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.



from CSS-Tricks https://ift.tt/2Y54kCB
via IFTTT

No comments:

Post a Comment

Lightly Poking at the CSS if() Function in Chrome 137

We’ve known it for a few weeks now, but the CSS if() function officially shipped in Chrome 137 version . It’s really fast development for a...