编程知识 cdmana.com

Exclamation point usage in SCSS file - set default values for variables

As shown in the figure below :

$useTabsOnPDP: false !default;

https://stackoverflow.com/que...

The meaning is as follows :

!default stay Bootstrap Sass Often used in . It is similar to reverse !important. all Bootstrap Variables are used !default Set up , To allow developers to further customize the bootstrap . Use !default sass Only one variable that has not been set will be defined .

//Example1 Dress color = red
$auroras-dress-color: blue;
$auroras-dress-color: red;

//Example2 Dress color = red
$auroras-dress-color: blue !default;
$auroras-dress-color: red;

//Example3 Dress color = blue
$auroras-dress-color: blue;
$auroras-dress-color: red !default;

So why does it matter ? Bootstrap Is a package . Most people can't edit Bootstrap Source code . Never update the bootstrap source . To customize the bootstrap , You'll add your own variable file and compile it with the bootstrap code , But never touch the native boot package . Bootstrap sass The page describes how to customize and compile it in detail in the document .

as far as I am concerned ,Twitter Bootstrap Use LESS. On the other hand ,!default It's actually Sass Part of , For providing Sass Variable ($var) The default value is , This makes it invalid in the given context , Even in Sass It's the same with China .

Besides , I am here LESS No pairs were found in the document !default References to , as far as I am concerned , It is Sass Unique . Are you sure you're here Bootstrap Found this in the source code of , Not elsewhere ? Because to be honest, I don't remember in Bootstrap I've seen Sass/SCSS Code .

You can go to sass-lang Website doc part ( Variable ) Find the following exact definitions and decent explanations - The default value is :

Usually when you assign a value to a variable , If the variable already has a value , Its old value will be overwritten . however , If you are writing Sass library , You may want to allow your users to generate CSS Configure your library variables before . To achieve this ,Sass Provides !default sign . Only if the variable is undefined or its value is null when , Will assign a value to this variable . otherwise , Existing values will be used .

版权声明
本文为[JerryWang_ Wang Zixi]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/10/20211002145413081Z.html

Scroll to Top