简体   繁体   English

在 Firefox 和 Chrome 中正确实现 CSS Grid

[英]Correct implementation of CSS Grid in Firefox and Chrome

As concluded here , CSS Grid implement equal height elements across rows by using grid-auto-rows: 1fr .正如此处总结的那样,CSS Grid 通过使用grid-auto-rows: 1fr However, Chrome and Firefox manifest different behaviours when inserting rows with a height set to auto between the equal height rows.但是,Chrome 和 Firefox 在等高行之间插入高度设置为 auto 的行时表现出不同的行为。 That is, Chrome achieves equal height across rows when using the explicit grid-auto-rows: auto 1fr 1fr 1fr syntax but only equal height on a per row basis when using repeat like grid-auto-rows: auto repeat(3, 1fr);也就是说,当使用显式的grid-auto-rows: auto 1fr 1fr 1fr语法时,Chrome 实现grid-auto-rows: auto 1fr 1fr 1fr高度相等,但在使用像grid-auto-rows: auto repeat(3, 1fr);这样的repeat时,每行的高度仅相等grid-auto-rows: auto repeat(3, 1fr); while Firefox only achieves equal height on a per row basis regardless.而 Firefox 无论如何只能在每行的基础上实现相同的高度。

Please observe the following in both Firefox and Chrome:请在 Firefox 和 Chrome 中注意以下几点:

https://codepen.io/Hlsg/pen/eemRmm https://codepen.io/Hlsg/pen/eemRmm

https://codepen.io/Hlsg/pen/jGWQwM https://codepen.io/Hlsg/pen/jGWQwM

Interestingly, they both behave the same with this implementation, so I'm thinking this is more to do with their implementation of css repeat :有趣的是,他们在这个实现中的行为都是一样的,所以我认为这更多地与他们的css repeat实现有关:

https://codepen.io/Hlsg/pen/VWKPzq https://codepen.io/Hlsg/pen/VWKPzq

What's your take on this, and which browser do you think has the correct, standard aproach?您对此有何看法,您认为哪种浏览器具有正确的标准方法?

Interestingly, they both behave the same with this implementation, so I'm thinking this is more to do with their implementation of css repeat .有趣的是,他们在这个实现中的行为都是一样的,所以我认为这更多地与他们的 css repeat实现有关。

I think you're correct.我认为你是对的。

If you look at the spec definition for grid-auto-rows and grid-auto-columns , the repeat() notation does not appear to be an acceptable value.如果您查看grid-auto-rowsgrid-auto-columns的规范定义,则repeat()表示法似乎不是可接受的值。

The definition says that only track sizes are acceptable values.定义说只有轨道大小是可接受的值。 And the definition of "track size" does not include repeat() .并且“轨道大小”的定义不包括repeat()

So a violation of the spec or, at a minimum, unclear spec language, may lead to differing browser implementations.因此,违反规范,或者至少,规范语言不明确,可能会导致不同的浏览器实现。

https://www.w3.org/TR/css3-grid-layout/#auto-tracks https://www.w3.org/TR/css3-grid-layout/#auto-tracks

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

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