我的容器中有一些div
,它通常比所有这些div
组合得更高。我希望它们能够均匀排列,但不能作为一个整体。下面的图片应该解释我正在尝试做什么。有没有办法用bootstrap 3实现这种简单的方法?
答案 0 :(得分:5)
你可以用纯CSS做到这一点但是这对于flexbox来说实际上非常简单。
.parent {
display: flex;
flex-direction: column;
justify-content: space-around;
}
.child {
flex: 1 1;
}
这样的事情应该有用。
答案 1 :(得分:2)
这是 FlexBox 的完美用例:
.flex-container {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
-webkit-align-content: center;
-ms-flex-line-pack: center;
align-content: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.flex-item:nth-child(1) {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 0 auto;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
-webkit-align-self: center;
-ms-flex-item-align: center;
align-self: center;
}
<div class="flex-container">
<div class="flex-item">Hello</div>
<div class="flex-item">Hello</div>
<div class="flex-item">Hello</div>
</div>
答案 2 :(得分:1)
您可以使用display: felx
作为您的解决方案:
.sides{ display:inline-block; margin: 0 10px }
ul {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 150px;
padding: 10px;
margin: 0;
list-style: none;
background-color: grey;
}
#side1{ height: 100vh }
#side2{ height: 75vh }
#side3{ height: 50vh }
.box{
padding: 2px;
margin: 0 20%;
width: 60%;
box-sizing: border-box;
background-color: red;
color: white;
text-align: center;
}
<div class="sides">
<ul id="side1">
<li class="box">Line 1</li>
<li class="box">Line 2</li>
<li class="box">Line 3</li>
<li class="box">Line 4</li>
</ul>
</div><div class="sides">
<ul id="side2">
<li class="box">Line 1</li>
<li class="box">Line 2</li>
<li class="box">Line 3</li>
<li class="box">Line 4</li>
</ul>
</div><div class="sides">
<ul id="side3">
<li class="box">Line 1</li>
<li class="box">Line 2</li>
<li class="box">Line 3</li>
<li class="box">Line 4</li>
</ul>
</div>