我知道如果您事先知道该单位,您可以从SASS中的数字中删除单位:
$number: 16px;
$without-unit: 16px / 1px;
@warn $without-unit; // 16
Run Code Online (Sandbox Code Playgroud)
但是有可能在不知道单位是什么的情况下从一个数字中剥离单位吗?
@function strip-unit($number) {
// magic code here...
}
@warn strip-unit(16px); // 16
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建动态值,但到目前为止失败了.创建的像素值似乎失去了在计算中使用的能力.
$numericValue: 30;
$pixelValue: $numericValue+px;
// also tried $pixelValue: #{$numericValue}px;
$calc: $pixelValue * 2;
// also tried $calc: unquote($pixelValue) * 2;
Run Code Online (Sandbox Code Playgroud)
这会引发错误
语法错误:未定义的操作:"30px乘以2"