Sass 返回负数列表而不是减去它们 [英] Sass is returning a list of negative numbers instead of subtracting them
问题描述
我正在尝试使用长度进行数学运算:
I'm trying to do math operation with lengths:
$itemWidth: 25px;
$item2Width: 80px;
element {
width: $itemWidth/2-$item2Width/2-5px
}
但是输出-52.5px -5px
怎么做才对?
However, it outputs -52.5px -5px
How to do it right?
推荐答案
Sass 3.2 解析器似乎对您的运算符之间缺少空格感到困惑(它认为您的意思是负 5px 而不是减去 5px):
The Sass 3.2 parser seems to be confused by your lack of whitespace between the operators (it thinks you mean negative 5px rather than subtract 5px):
element {
width: $itemWidth / 2 - $item2Width / 2 - 5px;
}
这在 Sass 3.3 中已修复,但您需要将 Compass 升级到 1.0(因为 0.12 与 Sass 3.3 不兼容).
This is fixed in Sass 3.3, but you'll need to upgrade Compass to 1.0 (since 0.12 is incompatible with Sass 3.3).
请注意,Sass 总是将紧跟在破折号/连字符之前的数字视为否定.这意味着 1 -2
被视为包含正数 1 和负数 2 的数字列表,而不是计算负数 1.
Note that Sass will always treat numbers immediately preceded by a dash/hyphen as negation. This means that 1 -2
is treated as a list of numbers containing the positive number one and the negative number two, rather than evaluating to the negative number 1.
这篇关于Sass 返回负数列表而不是减去它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!