CSS: :not negation selector
Negation selector (:not)
tag:not(selectorList)-
Match tag if it does not match selector selectorList.
selectorList is any selector list.
tag is optional. It can be a simple selector (selecting by tag name, id, class etc) or a compound selector (combination of tag name, id, class etc). If empty, it means the universal selector (* any tag).
/* match p, only if it is not class x nor class y */ p:not(.x, .y) { border: solid 1px red; } /* match any descendant of p, only if it is not class x nor class y */ p :not(.x, .y) { border: solid 1px blue; }
Specificity
The specificity of tag:not(selectorList) is the specificity of selectorList.
Examples
/* any element inside body, but is not .y nor .y */ body :not(.x):not(.y) { border: solid 2px orange; }
/* inside h2, and is not span.x */ h2 :not(span.x) { border: solid 2px green; }
note, :not() is part of
pseudo-class functions.
CSS Selector. pseudo-class functions
CSS. Selectors
Selector types
Simple selectors
- CSS: type selector (tag name)
- CSS: universal selector (* any tag)
- CSS: class selector (.x)
- CSS: ID selector (#)
- CSS: attribute selector ([x])
Combinators
- CSS: descendant selector (space)
- CSS: child selector (>)
- CSS: adjacent sibling selector (+)
- CSS: subsequent sibling selector (~)
Selector list
Nesting syntax
Special selector
- CSS: :root selector
- CSS: no child selector
- CSS: first child, last child, only child selectors
- CSS: nth-child selector
- CSS: nth-child arg of selector
- CSS: nth-of-type selector
- CSS: pseudo-class selector (:)
- CSS: pseudo-element selector (::)
- CSS: :not negation selector
- CSS: :has descendant selector