SASS How to set a Variable to equal nothing?

后端 未结 3 1184
一向
一向 2020-12-29 02:32

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

$false:null;

-and-

$false:\" \";


        
相关标签:
3条回答
  • 2020-12-29 03:04

    Set the variable to 'false'

    $false: false;

    0 讨论(0)
  • 2020-12-29 03:06

    Sass is written in ruby which uses nil instead of null.

    @mixin myMixin($myVariable, $myOtherVariable){
      $false: nil;
      @if $myVariable == $false{
         color: inherit;
      } @else {
         color: $myVariable;
      }
    }
    
    p {
      @include myMixin(nil, $myOtherVariable);
    }
    
    .red {
      @include myMixin(red, $myOtherVariable);
    }
    

    Example on jsFiddle

    0 讨论(0)
  • 2020-12-29 03:13

    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);
    
    0 讨论(0)
提交回复
热议问题