LoginSignup
17
15

More than 5 years have passed since last update.

【レスポンシブ】PCとスマホでdivの順番を入れ替える

Last updated at Posted at 2017-08-31

はじめに

flex-boxを使います。
スマホ(タブレット)のブレークポイントを768pxとしています。

Html

<div class="main">
  <div class="item1">1</div>
  <div class="item2">2</div>
  <div class="item3">3</div>
  <div class="item4">4</div>
</div>

CSS

.main{
  display: flex;
  flex-flow: row wrap;
}
.main div{width: 50%;}
.main .item1{order: 1;}
.main .item2{order: 3;}
.main .item3{order: 4;}
.main .item4{order: 2;}/*このセルの位置を操作*/
@media (max-width: 768px) {
  .main{display: block;}
  .main div{width: 100%;}
}

表示

PC

赤いセルを右上に表示
pc.png

スマホ

赤いセルを一番下に表示
sp.png

17
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
15