此代码停止使用最近版本的Chrome(例如52& 53),但它仍在使用Chrome 49和最新的Firefox版本。
基本上,当垂直空间很小时,textarea的容器缩小到0,因为所有其他非弯曲元素都需要空间,而不是考虑textarea的最小高度。
知道如何克服这个问题吗?
谢谢!
* {
box-sizing: border-box;
}
html,body {
margin:0;
}
html, body, app {
height:100%;
overflow:hidden;
}
app {
background-color: cyan;
padding: 10px;
}
[flexlayout] {
display: flex;
flex-direction: column;
min-height: 0;
}
[flex] {
flex: 1;
}

<app flexlayout>
<div flex flexlayout>
<div flex flexlayout style="flex-shrink:0;">
<!-- NON-FLEXED ELEMENT -->
<div>pokemon</div>
<!-- FLEXED ELEMENT -->
<div flex flexlayout>
<textarea flex style="min-height:250px;"></textarea>
</div>
<!-- NON-FLEXED ELEMENT -->
<div>
<p>charmander</p>
<p>squirtle</p>
<p>bulbasaur</p>
<p>pikachu</p>
<p>growlithe</p>
<p>slowpoke</p>
<p>eevee</p>
</div>
</div>
</div>
</app>
&#13;
答案 0 :(得分:1)
当你在textarea包装器上使用这些样式时会发生什么:
flex: 1;
min-height: 0;
此代码执行此操作:
flex-shrink: 1
,它允许灵活项目缩小flex-basis: 0
,即忽略内容的高度(textarea)min-height: 0
为overflow
时,visible
会阻止textarea强制执行容器的最小高度。您可以使用默认的min-height: auto
* {
box-sizing: border-box;
}
html, body {
margin:0;
}
html, body, app {
height:100%;
overflow:hidden;
}
app {
background-color: cyan;
padding: 10px;
}
[flexlayout] {
display: flex;
flex-direction: column;
min-height: 0;
}
[flex] {
flex: 1;
}
.textarea-wrapper {
min-height: auto;
}
&#13;
<app flexlayout>
<div flex flexlayout>
<div flex flexlayout style="flex-shrink:0;">
<!-- NON-FLEXED ELEMENT -->
<div>pokemon</div>
<!-- FLEXED ELEMENT -->
<div flex flexlayout class="textarea-wrapper">
<textarea flex style="min-height:250px;"></textarea>
</div>
<!-- NON-FLEXED ELEMENT -->
<div>
<p>charmander</p>
<p>squirtle</p>
<p>bulbasaur</p>
<p>pikachu</p>
<p>growlithe</p>
<p>slowpoke</p>
<p>eevee</p>
</div>
</div>
</div>
</app>
&#13;
或使flex-basis
成为内容的高度并防止收缩:
flex-basis: auto;
flex-shrink: 0;
* {
box-sizing: border-box;
}
html, body {
margin:0;
}
html, body, app {
height:100%;
overflow:hidden;
}
app {
background-color: cyan;
padding: 10px;
}
[flexlayout] {
display: flex;
flex-direction: column;
min-height: 0;
}
[flex] {
flex: 1;
}
.textarea-wrapper {
flex-basis: auto;
flex-shrink: 0;
}
&#13;
<app flexlayout>
<div flex flexlayout>
<div flex flexlayout style="flex-shrink:0;">
<!-- NON-FLEXED ELEMENT -->
<div>pokemon</div>
<!-- FLEXED ELEMENT -->
<div flex flexlayout class="textarea-wrapper">
<textarea flex style="min-height:250px;"></textarea>
</div>
<!-- NON-FLEXED ELEMENT -->
<div>
<p>charmander</p>
<p>squirtle</p>
<p>bulbasaur</p>
<p>pikachu</p>
<p>growlithe</p>
<p>slowpoke</p>
<p>eevee</p>
</div>
</div>
</div>
</app>
&#13;