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?

More than 5 years have passed since last update.

CSS:サイズ指定は比率・相対指定

Last updated at Posted at 2020-10-23

フォントサイズ、余白、幅などの指定は相対的に

 レスポンシブデザインのポイントになるのは「サイズ」。
 「サイズ」は、画面の幅によって動的に変動させる。
 また、ブレークポイントによって異なるサイズを指定しないといけない。

 このとき、いろいろなパーツに個別のサイズを指定していたのでは管理が大変。
 なので、その画面の起点となるサイズを定めたら、それの比率で他のサイズを決めていく。
 ブレークポイントごとに、その起点のサイズを変える。
 以下は、サンプル。

sample.sass

/* mixin:タイトルの集合 */
+titles($baseFontSize)
  .title
    font-size: $baseFontSize
  .sub-title
    font-size: $baseFontSize * 0.8  

/** デスクトップ以外 **/

//デスクトップの基準サイズ
$pcBaseSize: 1vw 
.container
  =titles($pcBaseSize)

/** デスクトップ以外 **/
@media screen and (max-width: $desktop)

//デスクトップの基準サイズ
$spBaseSize: 3vw
.container
  =titles($spBaseSize)

 
コード量を減らせるだけでなく、文字間のバランスを統一的にできるので、個別指定よりは相対的な指定をする方がよいと思います。

「多行は悪」がコーディングの指針ですね。

 
 
 

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?