Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the !default keyword in bootstrap and foundation scss frameworks used for? [duplicate]

Example:

$link-color: $mycolor !default;

I have a theory, but I want to validate it here. I know that initial is used to set an attribute back to the browsers default. Using !default overrides the browser's native default value and replaces $link-color with the value of $mycolor from the example above.

Am I understanding that correctly?

Attempts at googling this question has lead me to many blog posts about the bootstrap and foundation frameworks, but I have not found a straightforward answer to what !default specifically does. I'm guessing because google ignores the bang (!) so it looks like I'm asking about some other kind of default value.

Thanks

like image 474
rakitin Avatar asked Oct 26 '13 19:10

rakitin


1 Answers

!default is part of Sass' variables handling. The generated CSS which reaches the browser will never contain "!default".

Quoting the docs:

Variable Defaults: !default

You can assign to variables if they aren’t already assigned by adding the !default flag to the end of the value. This means that if the variable has already been assigned to, it won’t be re-assigned, but if it doesn’t have a value yet, it will be given one.


$link-color is merely a variable. In framework context, !default is used to not overwrite customizations made by you or other included modules, while providing a default value for the variable if it hasn't been given a value yet.

like image 174
Fabrício Matté Avatar answered Sep 29 '22 11:09

Fabrício Matté