【发布时间】:2016-11-16 14:14:51
【问题描述】:
我有一个 flex 列容器,里面有 2 个 div。第一个 div 有 flex: 1 以使其与剩余空间一起增长。第二个 div 有一个固定的高度。请注意,容器位于占据整个视口的固定 div 内。
问题是当容器太小放不下内容时,第一个div的内容在第二个下面溢出。
.test {
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: red;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
//min-height: 500px;
}
.child1 {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
flex: 1;
}
.child2 {
width: 100%;
display: flex;
justify-content: center;
}
span {
padding: 20px;
}
span:first-child {
margin-top: auto;
}
span:last-child {
margin-bottom: auto;
}
<div class="test">
<div class="child1">
<span>Test1</span>
<span>Test2</span>
<span>Test3</span>
<span>Test4</span>
<span>Test5</span>
<span>Test6</span>
<span>Test7</span>
<span>Test8</span>
</div>
<div class="child2">
<span>Test1</span>
<span>Test2</span>
<span>Test3</span>
<span>Test4</span>
</div>
</div>
一种解决方案可能是在容器上设置一个最小高度,但这不是一个动态和响应式的解决方案。
谁能告诉我当整个内容不适合时如何在容器上实现溢出行为?
【问题讨论】:
-
任何使用位置的理由:固定; ??原因:codepen.io/gc-nomade/full/jAaoGQ / codepen.io/gc-nomade/pen/jAaoGQ 很好....
-
@GCyrillus
position: fixed用于我的重叠菜单。我只是确保一切都像我的项目一样。 -
好的,然后添加一个溢出来修复它并更新 flex 值(包括 chrome)codepen.io/gc-nomade/pen/EybzpV