Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minmax fails (invalid property value)

Tags:

css

css-grid

Chrome gives an invalid property value and doesn't respect the CSS:

grid-template-columns: repeat(auto-fill, minmax(auto, 1fr));

It also fails when auto is replaced with min-content and max-content.

It works as expected when auto is replaced by a fixed value e.g.

grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));

This is surprising because both repeat and minmax support the keywords.

The html is simple

<div class='wrapper>
  <div>...</div>
  <div>...</div>
</div>

and css

.wrapper {
  display: grid
  grid-template-columns: repeat(auto-fill, minmax(auto, 1fr));
}
like image 422
Brian M. Hunt Avatar asked Jul 26 '17 17:07

Brian M. Hunt


People also ask

What does Minmax mean in CSS?

The minmax() CSS function defines a size range greater than or equal to min and less than or equal to max. It is used with CSS Grids.

What does Minmax 0 1fr mean?

When you use minmax(0, 1fr) , that's something different than standalone 1fr . In the first case, the track cannot be smaller than the size of the grid item (min size is auto ). In the second case, the track is free to resize to a 0 width/height.

How does Minmax function work?

The minimax algorithm helps find the best move, by working backwards from the end of the game. At each step it assumes that player A is trying to maximize the chances of A winning, while on the next turn player B is trying to minimize the chances of A winning (i.e., to maximize B's own chances of winning).

How does Minmax work in grid?

CSS Grid minmax() ValidationIf the min value in minmax(min, max) is larger than the max, then the max will be ignored. The minmax(min, max) will be treated as a min value. Also, it's important to keep in mind that using 1fr for the min value will be invalid. It only works for the max value.


1 Answers

When using auto-fill or auto-fit, there must be a definite min-size or max-size.

By "definite", the spec means:

A size that can be determined without measuring content.

https://www.w3.org/TR/css-sizing-3/#definite

When you set both minmax arguments to content-based size, like this:

grid-template-columns: repeat(auto-fill, minmax(auto, 1fr));

... that's a violation of the spec because there is no definite size.

Using min-content and max-content would result in the same error for the same reason.

As long as one value is definite, and the first value is not fr (see below), the rule is valid.

7.2.2.2. Repeat-to-fill: auto-fill and auto-fit repetitions

When auto-fill is given as the repetition number, if the grid container has a definite size or max size in the relevant axis, then the number of repetitions is the largest possible positive integer that does not cause the grid to overflow its grid container (treating each track as its max track sizing function if that is definite or as its minimum track sizing function otherwise, and taking grid-gap into account).

If any number of repetitions would overflow, then 1 repetition.

Otherwise, if the grid container has a definite min size in the relevant axis, the number of repetitions is the smallest possible positive integer that fulfills that minimum requirement.

Otherwise, the specified track list repeats only once.

like image 76
Michael Benjamin Avatar answered Oct 19 '22 05:10

Michael Benjamin