我想使用flexbox来进行列布局,但是我希望前 n - 1
个flex项目固定在顶部,而第 n
个flex项目固定在主要的flex容器区域的底部。
我通过使用第 n
个flex项目作为新的flexbox/flex容器,并使用 justify-content: flex-end
来解决这个问题,但我找不到任何这样做的示例 - 所以根据标准,这是正确/可接受的解决方案吗?如果不是,那么我该如何使用flexbox解决这个问题呢?
以下是一个快速示例:
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
width: 300px;
height: 240px;
background-color: Silver;
}
.flex-container-bottom {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
width: 300px;
height: 240px;
background-color: orange;
-webkit-justify-content: flex-end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.flex-item {
background-color: DeepSkyBlue;
width: 100px;
height: 100px;
margin: 5px;
}
.flex-item-bottom {
background-color: red;
width: 100%;
height: 50px;
}
<div class="flex-container">
<div class="flex-item">flex item 1</div>
<div class="flex-item flex-container-bottom">
<div class="flex-item-bottom">flex item 2</div>
</div>
</div>