2017-02-24 4 views
0

私は以下のように通常のhtml/cssレイアウトを持っています。しかし、最大幅480ピクセルの場合、section1とsection2の順序を逆にしたいと考えています。私はブートストラップを使用します。最大幅480pxの行の順番を逆にする

section1行の前にsection2行が必要です。どうやってやるの?

<div class="container" id="content"> 
     <div class="row" id="section1"> 
     </div> 
     <div class="row" id="section2"> 
     </div> 
     <div class="row" id="section3"> 
     </div> 
    </div> 
    <footer> 
    </footer> 
+0

フレックスボックスの使用をお勧めします。私はポストする例を考え出すつもりです。 – haltersweb

+0

プルクラスとプッシュクラスを調べます。 – CBroe

答えて

1

フレックスボックスを使用して、再オーダーする子供のorderプロパティを変更することができます。ここで

@media (max-width: 480px) { 
 
    .container { 
 
    display: flex; 
 
    flex-direction: column; 
 
    } 
 
    #section2 { 
 
    order: -1; 
 
    } 
 
}
<div class="container" id="content"> 
 
    <div class="row" id="section1">1 
 
    </div> 
 
    <div class="row" id="section2">2 
 
    </div> 
 
    <div class="row" id="section3">3 
 
    </div> 
 
</div>

+0

この解決策は私のために働いた。 – GJain

+0

@AndreiGheorghiuは私の言い訳ですか? OPのコードは、同じクラスとIDを持っています... –

0

のみ最初の前に、第二のボックスを移動するために、特定のメディアクエリで順序を使用してフレキシボックスのオプションです。残りの注文は同じです:

.container { 
    display: flex; 
    flex-wrap: wrap; 
} 
.row { 
    width: 100%; 
    height: 3em; 
    border: 1px solid red; 
    order: 2; 
} 
@media (max-width: 600px) { 
    #section2 { 
    order: 1; 
    } 
} 
関連する問題