考虑以下sass:
$font-size: 18;
$em: $font-size;
$column: $font-size * 3; // The column-width of my grid in pixels
$gutter: $font-size * 1; // The gutter-width of my grid in pixels
$gutter-em: #{$gutter / $em}em; // The gutter-width in ems.
$column-em: #{$column / $em}em; // The column-width in ems;
$foo = $gutter-em / 2; // This results in a value like "1em/2". :(
$bar = ($gutter-em / 2); // this doesn't work either, same as above.如何才能生成有效的$foo,并且可以在其他表达式中进一步重用?
发布于 2011-11-24 18:08:53
Sass不能对字符串执行算术运算,只能进行连接。当您使用插值时,您创建的是一个看起来像数字的字符串:
@debug type-of(#{10px}); // string
@debug type-of('10px'); // string
@debug type-of(unquote('10px')); // string
@debug type-of(10px); // number如果你想要一个数字,不要使用插值,也不要使用引号。用于转换整数(例如,10)设置为一定长度(例如10px),使用乘法:
$gutter-em: ($gutter / $em) * 1em;
@debug type-of($gutter-em); // numberhttps://stackoverflow.com/questions/8254941
复制相似问题