minmax() defaulting to max

In general, tracks will try to reach their max size:

If the free space is positive, distribute it equally to the base sizes of all tracks, freezing tracks as they reach their growth limits (and continuing to grow the unfrozen tracks as needed).

(In this context, “growth limit” is mostly a synonym for “max size in minmax()”.)

This happens to usually be what you want the track to do.

To get the effect you’re looking for, where it wraps tightly but won’t go above a certain limit, you can tweak what you’re doing a bit:

  • use minmax(50px, min-content) on the row sizes; this’ll wrap them tight to the contents, but won’t let them shrink below 50px.
  • use max-height: 150px on the actual grid items, so they’ll max out at 150px.

These two together should achieve the effect you want.

Leave a Comment