SASS 如何将变量设置为零? [英] SASS How to set a Variable to equal nothing?

查看:39
本文介绍了SASS 如何将变量设置为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个等于零的变量.我已经尝试了以下..

I am trying to create a variable that is equal to nothing. I have tried the following..

$false:null;

-和-

$false:" ";

我想用它来做什么...

What I am trying to use it with is this...

@mixin myMixin($myVariable:"", $myOtherVariable){
    $false:null;
    @if $myVariable == $false {
       //do something
    }
    @if $myVariable != "" {
      //do something else
    }
}

@include myMixin("", $myOtherVariable);

我在此示例中使用了两个变量,但我计划使用两个以上.

I am using two variables for this example, but I plan to have more than two.

基本上我想要做的是可以选择排除变量而不必使用空引号.$false: ""; 的问题在于它仍然需要空引号.所以我想知道 SASS 中是否有内置的东西来指定null/or nothing".我认为它可能为空.但似乎并非如此..

Basically what I want to do is have the option to exclude a variable without having to use empty quotes. And the problem with $false: ""; Is that it still expects empty quotes. So I am wondering if there is something built into SASS to designate "null / or nothing". I thought it might be null. But that doesn't seem to be the case..

推荐答案

nullfalse 会起作用(null 是最新的Sass 版本).两者都适用于您的示例.null 的唯一优点是,如果您将它与属性一起使用,它就会消失.

null or false will work (null is new in the latest version of Sass). Both will work for your example. The only advantage of null is that it disappears if you use it with a property.

@mixin myMixin($myVariable: false, $myOtherVariable: false){
  @if not $myVariable {
     //do something
  } @else {
    //do something else
  }
}

@include myMixin(false, $myOtherVariable);

这篇关于SASS 如何将变量设置为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆