Sass is returning a list of negative numbers instead of subtracting them

前端 未结 2 874
长情又很酷
长情又很酷 2020-12-12 04:02

I\'m trying to do math operation with lengths:

$itemWidth: 25px;
$item2Width: 80px;

element {
    width: $itemWidth/2-$item2Width/2-5px
}

2条回答
  •  眼角桃花
    2020-12-12 04:42

    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;
    }
    

    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).

    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.

提交回复
热议问题