【发布时间】:2020-08-06 22:58:34
【问题描述】:
我用height:0 flex-grow:1 制作了两个部分,并将它们设置为max-height: max-content,这样它们就不会增长太多,当它们包含大量元素时,每个部分将占用50% 的垂直空间。这是一个例子:https://jsfiddle.net/3wogy5q4/17/
问题是 max-height: max-content 在 Chrome 和 Fireforx 上被忽略,但仅在某些计算机上。你们知道为什么有些电脑会忽略max-content 以及如何替换它吗?
.main-screen {
height: 60vh;
background-color: yellow;
}
.col {
background-color: red;
height: 100%;
width: 100px;
display: flex;
flex-direction: column;
}
.first {
background-color: blue;
width: 95%;
overflow: auto;
height: 0;
flex-grow: 1;
max-height: max-content;
}
.second {
background-color: green;
width: 95%;
overflow: auto;
height: 0;
flex-grow: 1;
max-height: max-content;
}
<div class="main-screen">
<div class="col">
<div class="first">
<div>First</div>
<div>First</div>
<div>First</div>
<div>First</div>
<div>First</div>
<div>First</div>
<div>First</div>
<div>First</div>
</div>
<div class="second">
<div>Second</div>
<div>Second</div>
<div>Second</div>
<div>Second</div>
</div>
</div>
</div>
【问题讨论】:
-
我没有在我的计算机上看到问题,但您似乎想要
max-height: min-content;而不是max-height: max-content,这意味着最大值应该是他们需要的最小空间量。 -
max-content === min-content === auto表示高度。 -
@JacobP min-content 也可以正常工作,但不能解决问题。 “幸运的是”这个问题也出现在我的电脑上,我运行的是最新的 Chrome 84.0.4147.105