CSS Pseudo-class :not
Structure
:not(y)
Description
This selector selects elements that can't be selected with the selector y
. For example, this allows us to select all element that
are not paragraphs: by using *:not(p)
. This selector is also helpful for the context of inherited selectors. For example, we can select every element in a table that is not a td
: table *:not(td)
. You also can exclude IDs and classes: div:not([class="error"])
or just div:not(.error)
. You are not allowed to use a :not()
inside a :not()
which is no big problem, because that would be equal to a normal selector.
Examples
ul *:not(li) {display:none;}
*:not(div) {margin:0;}
p:not(#special) {padding:10px;}
Compatibility
Chrome | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|
14+ | 3+ | 9+ | 11.1+ | 4.0+ |