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.

【 SCSS / Sass 】calc で変数を使用する方法

Posted at

使い方を時々忘れるのでメモ。

Sassの公式リファレンス - calc(), element(), progid:...(), and expression()に使い方が記載されている。

OKパターン

#{変数}のように括る。

// SCSS
$sidenav-width: 100px;
.bl_sidenav {
  width: $sidenav-width;
}
.bl_main {
  width: calc(100% - #{$sidenav-width});
}
// Sass
$sidenav-width: 100px;
.bl_main
  width: $sidenav-width;
.bl_sidenav
  width: calc(100% - #{$sidenav-width});

NGパターン

calc(100% - $sidenav-width)のように記述すると、$sidenav-width→100pxの変換がされず、widthのスタイルが適用されないので注意。

// SCSS
$sidenav-width: 100px;
.bl_sidenav {
  width: $sidenav-width;
}
.bl_main {
  width: calc(100% - $sidenav-width);
}
// Sass
$sidenav-width: 100px;
.bl_main
  width: $sidenav-width;
.bl_sidenav
  width: calc(100% - $sidenav-width);
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?