Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS How to set a Variable to equal nothing?

Tags:

sass

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

$false:null; 

-and-

$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.

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..

like image 290
Kris Hollenbeck Avatar asked Sep 20 '12 21:09

Kris Hollenbeck


People also ask

How can we set default value to the variable in Sass?

Description. You can set the default values for variables by adding ! default flag to the end of the variable value. It will not re-assign the value, if it is already assigned to the variable.

What is the correct way to define a variable in Sass?

Sass variables are simple: you assign a value to a name that begins with $ , and then you can refer to that name instead of the value itself.

How do you create a reference variable dynamically in Sass?

To make a dynamic variable is not possible in SASS as of now, since you will be adding/connecting another var that needs to be parsed once when you run the sass command. As soon as the command runs, it will throw an error for Invalid CSS, since all your declared variables will follow hoisting.


1 Answers

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); 
like image 187
Miriam Suzanne Avatar answered Sep 17 '22 13:09

Miriam Suzanne