简体   繁体   English

CSS minmax 无效属性值

[英]CSS minmax invalid property value

I want to set the minmax property for my grid-template-columns .我想为我的grid-template-columns设置minmax属性。 But for some reason I don't get it to work.但由于某种原因,我无法让它发挥作用。

Here's my code:这是我的代码:

.start {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-rows: auto;
    grid-gap: 2%;
}

<div class="start">
  <div class="news"></div>
  <div class="video"></div>
</div>

When I inspect the .start class in Chrome, it just says "invalid property value" for the minmax attribute.当我在 Chrome 中检查.start类时,它只显示minmax属性的“无效属性值”。

I just want a two-column layout which becomes a one-column layout when the viewport gets to narrow.我只想要一个两列布局,当视口变窄时它变成一列布局。

I think this is what you're after:我认为这就是你所追求的:

grid-template-columns: repeat(2, minmax(320px, 1fr));

For smaller screens, where you want one column, use a media query to run this:对于较小的屏幕,您需要一列,请使用媒体查询来运行:

grid-template-columns: 1fr;

The minmax() notation requires proper syntax. minmax()符号需要正确的语法。

That could be said about most CSS properties, except in this case, due to the many options and variations, the syntax is a bit complex and not so easy to understand.大多数 CSS 属性都可以这样说,除了在这种情况下,由于有许多选项和变体,语法有点复杂,不太容易理解。 In other words, it's relatively easy to create an invalid rule.换句话说,创建无效规则相对容易。

The proper syntax for minmax() is detailed in the chart below ( taken from the spec ).下表详细说明了minmax()的正确语法(取自规范)。

Notice that there is no option for minmax() followed by another minmax() in the track lists.请注意,曲目列表中没有minmax()后跟另一个minmax()选项。 That's why your rule is invalid.这就是为什么您的规则无效。

在此处输入图片说明

Here's the complete explanation:这是完整的解释:

The minmax() CSS function defines a size range greater than or equal to min and less than or equal to max. minmax() CSS 函数定义了一个大于或等于 min 且小于或等于 max 的大小范围。

/* <inflexible-breadth>, <track-breadth> values */
minmax(200px, 1fr)
minmax(400px, 50%)
minmax(30%, 300px)
minmax(100px, max-content)
minmax(min-content, 400px)
minmax(max-content, auto)
minmax(auto, 300px)
minmax(min-content, auto)

/* <fixed-breadth>, <track-breadth> values */
minmax(200px, 1fr)
minmax(30%, 300px)
minmax(400px, 50%)
minmax(50%, min-content)
minmax(300px, max-content)
minmax(200px, auto)

/* <inflexible-breadth>, <fixed-breadth> values */
minmax(400px, 50%)
minmax(30%, 300px)
minmax(min-content, 200px)
minmax(max-content, 200px)
minmax(auto, 300px)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM