Sass是串联而不是添加? [英] Sass is concatenating instead of adding?
本文介绍了Sass是串联而不是添加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要这样在SCSS代码中定义宽度:
I need to define a width in my SCSS code as so:
#example {
width: $currentWidth + 349 !important;
}
其中$currentWidth
由循环定义.
但是,Sass最终总是将两个数字连接起来,而不是进行算术运算.
However, Sass always ends up concatenating the two numbers instead of doing the arithmetic.
我也尝试过:
width: #{$currentWidth + 349}px !important;
这仍然会导致串联.
我想知道我在做错什么吗?我知道这是非常基础的,但是我似乎也找不到关于Sass如何处理算术的好信息
I'm wondering what I'm doing wrong? I know this is incredibly basic, but I also can't seem to find good information on how Sass handles arithmetic
推荐答案
假定$currentWidth
是整数.
SASS:
$currentWidth: 30;
#example {
width: unquote( ($currentWidth + 349) + 'px ' + !important );
}
CSS输出:
#example {
width: 379px !important;
}
您可以在这里进行测试:
You can test it here:
这篇关于Sass是串联而不是添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文