【发布时间】:2020-03-17 14:16:09
【问题描述】:
根据 MDN 文档 (https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-rows):
最小内容
是一个关键字,表示占据网格轨道的网格项的最大最小内容贡献。
所以,在这个例子中:
.grid {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: max-content max-content max-content min-content;
grid-template-areas:
"one aside"
"two aside"
"three aside"
"four aside"
}
.one {
background: red;
grid-area: one;
}
.two {
background: green;
grid-area: two;
}
.three {
background: blue;
grid-area: three;
}
.four {
background: yellow;
grid-area: four;
}
.aside {
background: grey;
grid-area: aside;
}
<div class="grid">
<div class="one">
One
</div>
<div class="two">
Two
</div>
<div class="three">
Three
</div>
<div class="four">
Four
</div>
<div class="aside">
Aside <br>
Aside <br>
Aside <br>
Aside <br>
Aside <br>
Aside <br>
Aside <br>
Aside <br>
</div>
</div>
为了获得“最小内容”值,为第四行评估的高度值是多少?
min-content 评估的 aside 网格区域第四行的高度是多少?
https://jsfiddle.net/oygf360r/
在@temani-afif cmets 之后编辑:
为了澄清问题。
我理解min-content 在这种情况下的行为。
我想知道的是,浏览器如何计算这个值,因为第二列在该行中没有任何内容,因为 aside 的内容 em> 列属于所有行。
在这种情况下,浏览器是否会忽略 aside 列进行比较?
或者这些元素有什么特殊价值?
我也将它标记为浏览器,因为它可能与它更相关。
【问题讨论】:
-
@Paulie_D 在定义其他“行”的高度方面发挥了作用。那么问题来了,为什么黄色的 min-content 是最大的呢?尝试更改行模板上 min-content 的顺序以查看行为
-
@Paulie_D 但为什么只有最小内容的内容正在扩展?尝试例如:
grid-template-rows: max-content min-content max-content min-content;,您会看到第二行和第四行正在扩展,而不是另一行