我想对所有内容应用css规则(* { color: red; }
)。将css规则应用于除一个标记之外的所有内容
但是,我该如何做到这一点,而不需要Javascript或将类应用到我希望它应用到的所有东西?
喜欢的东西:
*:not-type(div) {
color: red;
}
而且该文件将是:
<span>this is red</span>
<span>this is red</span>
<div>this is not red</div>
我想对所有内容应用css规则(* { color: red; }
)。将css规则应用于除一个标记之外的所有内容
但是,我该如何做到这一点,而不需要Javascript或将类应用到我希望它应用到的所有东西?
喜欢的东西:
*:not-type(div) {
color: red;
}
而且该文件将是:
<span>this is red</span>
<span>this is red</span>
<div>this is not red</div>
尝试这样的:
:not(div){
color: red;
}
doens't work http://jsfiddle.net/ubea4tv7/1/ – 2014-08-28 09:12:30
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_not – 2014-08-28 09:16:10
':not(div)'将匹配body元素。然后,div元素从中继承红色。 – Alohci 2014-08-28 09:17:08
尝试这样的:
*{
color: red;
}
div{
color: blue;
}
这个解决方案的问题在于,它不允许使用缺省或继承的颜色(':not')来保留'div'。 – 2014-08-28 09:21:46
要选择不同的div元素的一切你可以这样写:
:not(div) {
color: red;
}
注意:虽然此规则正确选择了除div之外的所有元素,但它不会阻止的div从其父级继承红色,这是默认行为。
如果你有' ...
为什么不应用一个类你不想为红色的东西和风格,覆盖呢? – Pete 2014-08-28 09:05:50