minmax 失败(无效 属性 值)

minmax fails (invalid property value)

Chrome 给出 invalid property value 并且不尊重 CSS:

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

auto替换为min-contentmax-content时也会失败。

auto 被固定值替换时,它按预期工作,例如

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

这令人惊讶,因为 repeatminmax 都支持关键字。

html简单

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

和css

.wrapper {
  display: grid
  grid-template-columns: repeat(auto-fill, minmax(auto, 1fr));
}

当使用auto-fillauto-fit时,必须有一个明确的最小尺寸或最大尺寸。

通过 "definite",规范表示:

A size that can be determined without measuring content.

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

当您将两个 minmax 参数设置为基于内容的大小时,如下所示:

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

...这违反了规范,因为没有确定的大小。

使用 min-contentmax-content 会出于同样的原因导致同样的错误。

只要有一个值是确定的,并且第一个值不是 fr(见下文),则规则有效。

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.