background-color:none 是有效的 CSS 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8739665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is background-color:none valid CSS?
提问by NarfkX
Can anyone tell me if the following CSS is valid?
谁能告诉我以下 CSS 是否有效?
.class {
background-color:none;
}
回答by James Allardice
You probably want transparent
as none
is not a valid background-color
value.
您可能想要transparent
asnone
不是有效值background-color
。
The CSS 2.1 specstates the following for the background-color
property:
在CSS 2.1规范规定了以下background-color
特性:
Value: <color> | transparent | inherit
Value: <color> | transparent | inherit
<color>
can be either a keyword or a numerical representation of a colour. Valid color
keywordsare:
<color>
可以是关键字或颜色的数字表示。有效的color
关键字是:
aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow
浅绿色、黑色、蓝色、紫红色、灰色、绿色、石灰、栗色、海军蓝、橄榄色、橙色、紫色、红色、银色、蓝绿色、白色和黄色
transparent
and inherit
are valid keywords in their own right, but none
is not.
transparent
andinherit
本身就是有效的关键字,但none
不是。
回答by Jitendra Vyas
No, use transparent
instead none
. See working example here in this example if you will change transparent
to none
it will not work
不,请transparent
改用none
。见工作示例这里在这个例子中,如果你将改变transparent
到none
它不会工作
use like .class { background-color:transparent; }
使用喜欢 .class { background-color:transparent; }
在哪里 .class.class是您将命名透明类的名称。
回答by Sajidur Rahman
The answer is no.
答案是不。
Incorrect
不正确
.class {
background-color: none; /* do not do this */
}
Correct
正确的
.class {
background-color: transparent;
}
background-color: transparent
accomplishes the same thing what you wanted to do with background-color: none
.
background-color: transparent
完成你想要做的同样的事情background-color: none
。
回答by Barun
.class {
background-color:none;
}
This is not a valid property. W3C validator will display following error:
这不是有效的属性。W3C 验证器将显示以下错误:
Value Error : background-color none is not a background-color value : none
值错误:背景颜色无不是背景颜色值:无
transparent
may have been selected as better term instead of 0
or none
values during the development of specification of CSS.
transparent
可能在 CSS 规范的开发过程中被选为更好的术语而不是0
或none
值。
回答by Gert Hengeveld
CSS Level 3 specifies the unset
property value. From MDN:
CSS 级别 3 指定unset
属性值。来自MDN:
The unset CSS keyword is the combination of the initial and inherit keywords. Like these two other CSS-wide keywords, it can be applied to any CSS property, including the CSS shorthand all. This keyword resets the property to its inherited value if it inherits from its parent or to its initial value if not. In other words, it behaves like the inherit keyword in the first case and like the initial keyword in the second case.
unset CSS 关键字是initial 和inherit 关键字的组合。像这两个 CSS 范围内的其他关键字一样,它可以应用于任何 CSS 属性,包括所有的 CSS 速记。如果属性从其父级继承,则此关键字将属性重置为其继承的值,否则重置为其初始值。换句话说,它的行为类似于第一种情况下的 inherit 关键字,第二种情况下的行为类似于 initial 关键字。
Unfortunately this value is currently not supported in all browsers, including IE, Safari and Opera. I suggest using transparent
for the time being.
不幸的是,目前并非所有浏览器都支持该值,包括 IE、Safari 和 Opera。建议transparent
暂时使用。
回答by Abolfazl Miadian
write this:
写这个:
.class {
background-color:transparent;
}
回答by Binita Bharati
So, I would like to explain the scenario where I had to make use of this solution. Basically, I wanted to undo the background-color attribute set by another CSS. The expected end result was to make it look as though the original CSS had never applied the background-color attribute . Setting background-color:transparent;
made that effective.
所以,我想解释一下我必须使用这个解决方案的场景。基本上,我想撤消由另一个 CSS 设置的 background-color 属性。预期的最终结果是让它看起来好像原始 CSS 从未应用过 background-color 属性。设置background-color:transparent;
使之有效。