Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Advanced Sass Advanced Variables, Mixins, Functions, and Placeholders Scoping and !default Variables

Iulia Maria Lungu
Iulia Maria Lungu
17,357 Points

this behaviour is outdated in sass 3.4.21

It should be noted that in Sass 3.4.21 (Selective Steve), this scoping works like JavaScript, exactly as the deprecation warning shown in the terminal in this video.

This :

$text-color : blue;

h1 {
  $text-color: red;
  color: $text-color;

}

h2 {
  color: $text-color;
}

compiles to this:

h1 {
  color: red;
}

h2 {
  color: blue;
}

so $text-color remains in the global scope where it was first defined

1 Answer

What he's describing in the video still works. He announces in this video that if you want $text-color: red to become its default color you must pass the !global flag after red. So,

$text-color : blue;

h1 { 
$text-color: red !global; 
color: $text-color;

}

h2 { 
color: $text-color; 
} 

compiles to

h1 { 
color: red; 
}

h2 { 
color: red; 
}