我正在尝试创建一个等于零的变量。我尝试了以下方法。
$false:null;
-和-
$false:" ";
我正在尝试使用的是这个...
@mixin myMixin($myVariable:"", $myOtherVariable){
$false:null;
@if $myVariable == $false {
//do something
}
@if $myVariable != "" {
//do something else
}
}
@include myMixin("", $myOtherVariable);
在此示例中,我使用了两个变量,但我计划有两个以上。
基本上,我要执行的操作是可以选择排除变量,而不必使用空引号。
$false: "";
的问题在于它仍然期望使用空引号。因此,我想知道SASS是否内置某些东西来指定“null / or no”。我以为可能是空的。但这似乎并非如此。 最佳答案
null
或false
将起作用(null
是Sass的最新版本中的新增功能)。两者都适用于您的示例。 null
的唯一优点是,如果将它与属性一起使用,它将消失。
@mixin myMixin($myVariable: false, $myOtherVariable: false){
@if not $myVariable {
//do something
} @else {
//do something else
}
}
@include myMixin(false, $myOtherVariable);
关于sass - SASS如何将变量设置为等于零?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12521197/