5

我有这段代码,它使每个段落的类都不同于“ cl2”红色。

<head>
<style type="text/css">
p{ color:#000000; }
:not(.cl2){ color:#ff0000; }
</style>
</head>
<body>
<p class="cl1">This is a paragraph.</p>
<p class="cl2">This is second paragraph.</p>
<p class="cl2">This is third paragraph.</p>
<p class="cl3">This is fourth paragraph.</p>
<p class="cl2">This is fifth paragraph.</p>
<p class="cl2">This is sixth paragraph.</p>
<p class="cl4">This is seventh paragraph.</p>
<p class="cl5">This is eigth paragraph.</p>
<p class="cl1">This is nineth paragraph.</p>
</body>

如何扩展我的:not选择器以忽略例如类“ cl2”和“ cl4”?我试过了::not(.cl2, .cl4){ color:#ff0000; }但它不起作用。

4

1 回答 1

9
:not(.cl2):not(.cl4){ color:#ff0000; }

http://jsfiddle.net/nottrobin/WFwtP/

请注意CSS3 和 jQuery 中的选择器之间存在差异:not- 由于在 CSS4 规范中收敛(感谢@BoltClock)

于 2012-09-04T22:17:15.300 回答