CSS属性值中的!default是什么意思?

CSS

逆天Eva

2020-03-18

twitter引导程序代码具有许多CSS属性,!default最后带有一个

例如

p {
  color: white !default;
}

怎么!default办?

更新

我不好说不清楚。我正在使用Bootstrap的SASS部分。

第2087篇《CSS属性值中的!default是什么意思?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

2个回答
村村西里 2020.03.18

You can find the following exact definition and a decent explanation in sass-lang website in its doc section (variable) - default value:

Normally when you assign a value to a variable, if that variable already had a value, its old value is overwritten. But if you’re writing a Sass library, you might want to allow your users to configure your library’s variables before you use them to generate CSS. To make this possible, Sass provides the !default flag. This assigns a value to a variable only if that variable isn’t defined or its value is null. Otherwise, the existing value will be used.

西门神乐 2020.03.18

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

此外,我!defaultLESS文档中找不到任何引用,据我所知,它仅属于Sass。您确定在Bootstrap的源代码中找到了这个吗?因为老实说,我不记得在Bootstrap的样式表中看到Sass / SCSS代码。

就其价值而言,!CSS中唯一以开头的有效令牌!important您可能已经知道了

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android