4
這裏是我的代碼片段:如何將兩個div放在垂直排序的flex div的一行中?
.container {
display: flex;
flex-direction: column;
}
.container > div {
padding: 20px;
color: #fff;
margin: 5px;
text-align: center;
font-size: 30px;
}
.fruits {
order: 2;
background: #ff5423;
}
.container :not(.fruits) {
order: 1;
}
.flowers {
background: #f970bd;
}
.trees {
background: #049500;
}
<div class="container">
<div class="fruits">The fruits</div>
<div class="flowers">The flowers</div>
<div class="fruits">The fruits</div>
<div class="trees">The trees</div>
<div class="fruits">The fruits</div>
</div>
我把所有.fruits
格在底部使用flex-direction: column;
。還有另外兩個div .flowers
和.trees
,它們可以隨機放置在.conatiner
的任何地方,我無法處理。我希望它們佔據其父寬度的一半,因此它們只佔用一行。
給予50%的寬度不會在這裏工作。我知道規則說明了方向是列式的,但是,我仍然希望如果有任何可用的方法/技巧這樣做!使用不同技術而不是使用flex的任何其他解決方法也將有所幫助。
真棒!你搖滾! :) –