![]() |
VOOZH | about |
SASS allows a user to declare some default values to variables which can be used if the variable is not declared or assigned a value of 'null'. If a variable is declared with some value , then that value is overwritten over the default value. In SASS , the default variable is assigned with the !default tag.
Syntax of default variable :
$color: black !default ; //black is the default value to the variable 'color'
In SASS , one can write two variables with exactly same name : one global and one local. In such condition , user may mistakenly change the value of global variable by changing the value of the local variable. To avoid such a condition, SASS has the shadowing feature, in which on writing a local variable inside a local scope doesn't necessarily change the value of the global variable.
Given below is an example to show the above functionality :
//SASS Code file $colour: black; .nav $colour: blue; background-color: $colour; .p background-color: $colour;
The above code when compiled to native CSS becomes:
Now, to change the value of the global variable from the local scope , we need to mention the "!global" tag beside the variable as shown below:
//SASS Code file\ $colour: black; .nav $colour: blue !global; background-color: $colour; .p background-color: $colour;
The above code when compiled to native CSS becomes :
Flow Control Scope helps to define the values of the variables based on the flow of the program. They makes the code much easier to understand and makes the code just like the other programming languages like Java , C++ etc. It changes the values of some of the variables based on the value of some other variables or features. Given below is an example code that displays flow control rules of variables:
//SASS Code file $bool: true; $font_color: blue; $bg_color: skyblue; @if $bool $font_color: violet; $bg_color: pink; .nav background-color: $bg_color color: $font_color
The above code when compiled to native CSS :