0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CSSのレスポンシブ対応の書き方いつも忘れちゃうのでメモ。

Last updated at Posted at 2021-12-15

CSS書くたびに

「あれ…?『max-width:1024px』ってどういう意味だっけ…?
カチャカチャ(検索)…あぁ『1024pxより幅が狭い場合は適応』か。』

みたいな流れを繰り返しているので、メモしておく。

PCを基準にコーディングする場合

body{
  background-color: whitesmoke;
}

/* PCだけに適応する */
@media only screen and (min-width: 1025px) {
  body{
    background-color: whitesmoke;
  }
}

/* タブレット用のブレークポイント */
@media only screen and (max-width: 1024px) {
  body{
    background-color: #c4ffcb;
  }
}

/* スマホ用のブレークポイント */
@media only screen and (max-width: 599px) {
  body{
    background-color: #8ddef7;
  }
}

スマホを基準にコーディングする場合

body{
  background-color: #8ddef7;
}

/* タブレット用のブレークポイント */
@media only screen and (min-width: 600px) {
  body{
    background-color: #c4ffcb;
  }
}

/* PC用のブレークポイント */
@media only screen and (min-width: 1025px) {
  body{
    background-color: whitesmoke;
  }
}

そのままコピペしたら背景色がブレークポイントごとに変わるはず。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?