Sass是连接而不是添加?

时间:2013-09-05 14:34:24

标签: css math sass

我需要在我的SCSS代码中定义宽度:

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

循环定义$currentWidth

然而,Sass总是最终连接两个数字而不是算术。

我也尝试过:

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

这仍然导致连接。

我想知道我做错了什么?我知道这是非常基本的,但我似乎也无法找到关于Sass如何处理算术的好信息

1 个答案:

答案 0 :(得分:31)

假设$currentWidth是一个整数。

<强> SASS:

$currentWidth: 30;

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

CSS OUTPUT:

#example {
  width: 379px !important;
}

你可以在这里测试一下:

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