正如所承諾的,一個簡單的draft
HTML
<div class="row">
<div class="col1">DIV A</div>
<div class="col2">DIV B</div>
<div class="col3">DIV C</div>
</div>
CSS
.row {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
width: 400px;
margin: 0 auto;
}
.col1 {
width: 200px;
height: 400px;
background-color: #86a0ff;
}
.col2 {
width: 150px;
height: 150px;
background-color: #ff6cde;
}
.col3 {
margin-top: -200px;
margin-left: auto;
width: 150px;
height: 150px;
background-color: #35af6d;
}
@media (max-width: 768px) {
.row {
justify-content: center;
flex-direction: column;
}
.col1 {
order: 2;
width: 200px;
margin-top: 50px;
}
.col2 {
order: 1;
width: 200px;
}
.col3 {
order: 3;
width: 200px;
margin-top: 50px;
margin-left: 0;
}
}
至於解釋,這裏是一個偉大的guide了flexbox。在我的例子中,主要思想是通過使用順序屬性可以控制塊顯示的順序。使用flexbox的主要優點是您不需要加載任何庫(如Bootstrap)以實現所需的結果,例如響應。它也有一個很好的瀏覽器support,除非你需要支持舊版本的瀏覽器。我希望我的回答對你有幫助!
我不認爲在引導程序中有任何類可以改變元素的順序。 –
@Mr_Green fwiw,當前使用的HTML結構未鎖定。我們可以做任何我們想做到的事情。 – naomik
您是否嘗試過使用Flexbox? – Olga