什么!默认的css属性值是什么意思?

时间:2021-08-12 18:36:26

The twitter bootstrap code has a lot of CSS properties with a !default at the end.

twitter的bootstrap代码有很多CSS属性,最后是默认值。

E.g.

如。

p {
  color: white !default;
}

What does !default do?

什么!违约怎么办?

UPDATE

更新

My bad for not being clear. I am using the SASS port of Bootstrap.

我的错在于没有说清楚。我正在使用Bootstrap的SASS端口。

2 个解决方案

#1


33  

Twitter Bootstrap uses LESS as far as I've seen. On the other hand, !default is actually part of Sass, and is used for giving Sass variables ($var) default values, which would make it invalid in your given context, even in Sass.

据我所见,Twitter Bootstrap的使用量更少。另一方面,!default实际上是Sass的一部分,用于提供Sass变量($var)默认值,这将使它在给定的上下文中无效,即使在Sass中也是如此。

Besides, I've not been able to find any references to !default in the LESS documentation, and to my knowledge it is exclusive to Sass. Are you sure you found this in Bootstrap's source and not elsewhere? Because I honestly don't remember seeing Sass/SCSS code in Bootstrap's stylesheets.

此外,我还没有找到任何参考资料!缺省在较少的文件,而且据我所知它是唯一的Sass。你确定你是在Bootstrap的源代码中找到的吗?因为我真的不记得在Bootstrap的样式表中看到过Sass/SCSS代码。

For what it's worth, the only valid token that starts with ! in CSS is !important, which you may already be aware of.

不管它的价值是什么,唯一有效的标记开始!在CSS中是很重要的,你可能已经知道了。

#2


24  

!default is used often in Bootstrap Sass. It is similar to a reverse !important. All of Bootstraps Variables are set using !default to allow the developer to further customize bootstrap. With !default sass will only define a variable if it has not already been set.

!缺省值通常用于引导Sass。这就像颠倒过来一样,很重要。所有引导变量都是使用!默认设置的,以允许开发人员进一步自定义引导。使用!默认sass将只定义一个尚未设置的变量。

This allows for more flexibility.

这允许更多的灵活性。

//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 is this important? Bootstrap is a package. Most people don't edit the Bootstrap source. NEVER UPDATE THE BOOTSTRAP SOURCE. To customize bootstrap you will add your own variable file and compile it with the bootstrap code but never touch the native bootstrap package. Bootstrap sass's page has the full skinny on how to customize and compile it in the documentations.

为什么这很重要呢?引导是一个包。大多数人不编辑引导源。不要更新引导源。要自定义bootstrap,您将添加您自己的变量文件,并通过引导代码编译它,但永远不要接触本机引导程序包。Bootstrap sass的页面在如何自定义和编译它的文档中有完整的细节。

I don't know why less does not do this. I have not worked much with less and do not know if it has it's own built in variable management.

我不知道为什么不这么做。我的工作很少,而且不知道它是否有自己的变量管理。

Example fiddle https://jsfiddle.net/siggysid/344dnnwz/

例如小提琴https://jsfiddle.net/siggysid/344dnnwz/

#1


33  

Twitter Bootstrap uses LESS as far as I've seen. On the other hand, !default is actually part of Sass, and is used for giving Sass variables ($var) default values, which would make it invalid in your given context, even in Sass.

据我所见,Twitter Bootstrap的使用量更少。另一方面,!default实际上是Sass的一部分,用于提供Sass变量($var)默认值,这将使它在给定的上下文中无效,即使在Sass中也是如此。

Besides, I've not been able to find any references to !default in the LESS documentation, and to my knowledge it is exclusive to Sass. Are you sure you found this in Bootstrap's source and not elsewhere? Because I honestly don't remember seeing Sass/SCSS code in Bootstrap's stylesheets.

此外,我还没有找到任何参考资料!缺省在较少的文件,而且据我所知它是唯一的Sass。你确定你是在Bootstrap的源代码中找到的吗?因为我真的不记得在Bootstrap的样式表中看到过Sass/SCSS代码。

For what it's worth, the only valid token that starts with ! in CSS is !important, which you may already be aware of.

不管它的价值是什么,唯一有效的标记开始!在CSS中是很重要的,你可能已经知道了。

#2


24  

!default is used often in Bootstrap Sass. It is similar to a reverse !important. All of Bootstraps Variables are set using !default to allow the developer to further customize bootstrap. With !default sass will only define a variable if it has not already been set.

!缺省值通常用于引导Sass。这就像颠倒过来一样,很重要。所有引导变量都是使用!默认设置的,以允许开发人员进一步自定义引导。使用!默认sass将只定义一个尚未设置的变量。

This allows for more flexibility.

这允许更多的灵活性。

//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 is this important? Bootstrap is a package. Most people don't edit the Bootstrap source. NEVER UPDATE THE BOOTSTRAP SOURCE. To customize bootstrap you will add your own variable file and compile it with the bootstrap code but never touch the native bootstrap package. Bootstrap sass's page has the full skinny on how to customize and compile it in the documentations.

为什么这很重要呢?引导是一个包。大多数人不编辑引导源。不要更新引导源。要自定义bootstrap,您将添加您自己的变量文件,并通过引导代码编译它,但永远不要接触本机引导程序包。Bootstrap sass的页面在如何自定义和编译它的文档中有完整的细节。

I don't know why less does not do this. I have not worked much with less and do not know if it has it's own built in variable management.

我不知道为什么不这么做。我的工作很少,而且不知道它是否有自己的变量管理。

Example fiddle https://jsfiddle.net/siggysid/344dnnwz/

例如小提琴https://jsfiddle.net/siggysid/344dnnwz/