21

次のように、SCSS コードで幅を定義する必要があります。

#example {
  width: $currentWidth + 349 !important;
}

where$currentWidthはループによって定義されます。

ただし、Sass は常に、算術を実行する代わりに 2 つの数値を連結してしまいます。

私も試しました:

width: #{$currentWidth + 349}px !important;

それでも連結が発生します。

私は何が間違っているのだろうか?これは信じられないほど基本的なことですが、Sass が算術演算を処理する方法に関する適切な情報を見つけることができないようです

4

1 に答える 1

37

$currentWidthが整数であると仮定します。

サス:

$currentWidth: 30;

#example {
  width: unquote( ($currentWidth + 349) + 'px ' + !important );
}

CSS出力:

#example {
  width: 379px !important;
}

ここでテストできます:

http://sass-lang.com/try.html

于 2013-09-05T20:47:02.127 に答える