Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

はじめに

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

saksak
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした