0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CSS remとemの単位 レスポンシブ

0
Posted at

理解しておく利点

親要素と子要素の比率の関係を変更したくない場合に実装が簡潔になる

em

「現在指定されているフォントサイズ」に対して相対的な大きさを指定

子要素のフォントサイズを指定しない場合

親要素のサイズが適用される。
例えば
親要素がfont-size: 40px;のとき、
中の子要素は、font-size: 40px;の大きさに。

子要素のフォントサイズを2emなどにした場合

親要素の二倍のサイズが適用される。
例えば
親要素がfont-size: 40px;のとき、
中の子要素は、font-size: 80px;の大きさに。

メリット

フォントサイズ(親要素)を変更すると、中の画像(子要素)も同じ比率で拡大縮小される

rem

「htmlで指定さているフォントサイズ」に対して相対的な大きさを指定

htmlタグはデフォルトサイズがfont-size: 16px;それに対して2倍や0.5倍

# デフォルトのフォントサイズを10pxに
html {
font-size: 62.5%;
}
# デフォルトのフォントサイズと同じ大きさにする
img {
width: 1rem;
}

メリット

プロジェクト全体でhtmlのフォントサイズを指定してそれを基準にできる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?