Quick notes on SCSS variables
When processed Sass will output the current variable value
$color: red;
.class-1 { color: $color; } // red
$color: blue;
.class-2 { color: $color; } // blue
You can use the !default flag to define default variables.
$color: red;
$color: blue !default; // only used if not defined earlier
.class-1 { color: $color; } // red
Inside function, mixins and selectors variables are local.
$color: red; // global
@mixin color {
$color: blue; // local
color: $color
}
.class-1 { color: $color; } // red (global)
.class-2 { @include color; } // blue (local)
.class-3 {
$color: green; // local
color: $color; // green (local)
}
.class-4 {
color: $color; // red (global)
}
You can use the !global flag to globalize variables.
$color: red; // global
@mixin color {
$color: blue !global; // global
color: $color
}
// as we are including color after printing class-1 the color is still red
.class-1 { color: $color; } // red
.class-2 { @include color; } // blue
// at this point the include in class-2 changed the color variable to blue
.class-3 { color: $color; } // blue