In this recipe, you will learn how to perform a conditional assignment of a variable or a property with SassScript.
Read the Installing Sass for command line usage recipe of Chapter 1, Getting Started with Sass, to find out how to compile your SCSS code into CSS code.
Perform the following step to learn more about conditional assignments in Sass:
Use your text editor to create a Ruby file called
if.rb
. Write down the following SCSS code into this file:// scss-lint:disable ColorKeyword $dark: true; $dark-color: black; $light-color: white; .element { color: if($dark, $dark-color, $light-color); }
Then, run the following command in your console to compile the Sass template from the first step into CSS code:
sass if.scss
Finally, a CSS code like the one shown here should be outputted in your console:
.element { color: black; }