Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 selector for "not A and not B"?

I have this code which makes every paragraph with class different than "cl2" red.

<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>

How can I extend my :not selector to ignore for example classes "cl2" AND "cl4"? I trided: :not(.cl2, .cl4){ color:#ff0000; } but it doesn't work.

like image 851
Tales Avatar asked Sep 04 '12 22:09

Tales


People also ask

What does not () do in CSS?

The :not() CSS pseudo-class represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.

What are the 3 selectors in CSS?

Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selectors (select elements based on a certain state)

What are the 4 CSS selectors?

A type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class is a simple selector.


1 Answers

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

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

Note there are differences between the :not selector in CSS3 vs jQuery - due to converge in the CSS4 spec (thanks @BoltClock)

like image 55
Robin Winslow Avatar answered Sep 21 '22 15:09

Robin Winslow