了解CSS网格中的溢出 / minmax行为
tldr:嵌套网格溢流的codepen列:重复(16,minmax(0,1fr));
因此,我有一个元素容器
,带有两个主要元素,summary-wrapper
和<代码> stats-wrapper
容器
具有以下网格:
.container {
display: grid;
grid-template-columns: repeat(16, 1fr);
column-gap: 4rem;
row-gap: 4rem;
padding: 5rem;
width: 100%;
}
summary-wrapper
放置在grid> grid-column:1/11;
(第96行)和 stats-wrapper
at 网格列:11/17;
(第25行)
在我心中,将统计数据的网格列更改为网格 - 列表:12/17
应该只移动元素的开始,它在chrome中进行:
chrome(无溢出):
但是在firefox中:
现在,浏览器之间的行为不同似乎有些怪异,但并没有真正改变我对网格容器的工作方式的心理模型只是……错误 - 而且我经历过(并且在我的项目中经历)这种行为在Chrome中,这并不是我问题的重点。
我以前有这个问题,但是有输入,并且被定向到这个答案这允许更长的元素使用<<<代码>网格 - 板块列:重复(16,minmax(0,1fr));
这似乎适用于STATS元素(如果您查找标题,则不再溢出页面)。但是,由于该元素的内容(不包括标头)也是嵌套网格的一部分,所以我遇到了同样的问题,但是它并未使用网格 - 板块 - 列来固定:重复(16,Minmax(Minmax(0,1fr)) );
(第50行)这次:
我觉得很奇怪,因为我看不出任何原因(无论哪种情况)需要溢出。甚至使用minmax(0,1fr)
的修复程序也依赖于说明
1fr等效于MinMax(Auto,1FR)
,并且auto
阻止轨道小于项目。但是在这种情况下(afaik)项目stats__section-查看
stats__section-sate-section-applications
and stats__section-stats__section-trend
,除了他们的文字,
我只是很困惑!
任何帮助!
TLDR: Codepen of nested grid overflowing and not being fixed by using grid-template-columns: repeat(16, minmax(0,1fr));
So I've an element container
, with two main elements, summary-wrapper
and stats-wrapper
container
has the following grid:
.container {
display: grid;
grid-template-columns: repeat(16, 1fr);
column-gap: 4rem;
row-gap: 4rem;
padding: 5rem;
width: 100%;
}
summary-wrapper
is placed at grid-column: 1/11;
(line 96) andstats-wrapper
at grid-column: 11/17;
(line 25)
In my mind, changing the grid column of the stats-wrapper to grid-column: 12/17
should just move the start of the element, which it does in Chrome:
Chrome (no overflow):
But in Firefox:
Now the behaviour being different between browsers seems a bit weird, but doesn't really change the fact that my mental model for how grid containers works is just... wrong - and I've experienced (and am experiencing in my project) this behaviour in Chrome, so that's not really the focus of my question.
I've had this issue before, but with inputs, and was directed to this answer that allows longer elements to collapse using grid-template-columns: repeat(16, minmax(0,1fr));
This seems to work for the stats element (if you look the header no longer overflows the page). But because the contents of that element (excluding the header) are part of a nested grid too, I get the same problem, but it's not fixed using grid-template-columns: repeat(16, minmax(0,1fr));
(line 50) this time:
I just find it very strange, as I can't see any reason why the elements (in either case) need to overflow. Even the fix using minmax(0,1fr)
relies on the explanation that
1fr is equivalent to minmax(auto, 1fr)
and that auto
is preventing the track being smaller than the item. But in this case (afaik) the items stats__section--viewed
stats__section--applications
and stats__section--trend
have no min size, other than their text
I'm just stumped!
Any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
溢出的原因是嵌套网格
.stats__content
中的列隙
规则。由于它是一个固定的宽度,重复15次(因为缝隙仅在轨道之间,而不在轨道和容器边缘之间),在这种情况下,溢出是不可避免的。
减少间隙的数量或找到其他解决项目的解决方案。
The reason for the overflow is a
column-gap
rule in the nested grid.stats__content
.Being that it's a fixed width, repeated 15 times (because gaps only go between tracks, not between tracks and container edges), an overflow is inevitable in this case.
Reduce the number of gaps or find another solution for separating the items.