I'm trying to use the CSS3 :not pseudo class as defined in the specification. According to the spec:
The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument. It represents an element that is not represented by its argument
So I would expect to be able to do something like this:
p:not(.class1, .class2)
But it does not seem to work in Safari or Firefox, which are supposed to have FULL support for this selector.
It does work when the argument is a single selector, for example:
Here is an example showing the issue: jsFiddle Example
p:not(.class1)
According to this blog post, this author suggests that you should be able to specify multiple selectors as the argument.
Also according to this CSS3 SitePoint Reference, Firefox, Safari and Chrome have FULL support for the :not selector.
Am I misinterpreting the specification or do browsers actually only have partial support for this selector?
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. The :not() pseudo-class has a number of quirks, tricks, and unexpected results that you should be aware of before using it.
It means that you can use new CSS as an enhancement, knowing that no error will occur if it is not understood — the browser will either get the new feature or not. This enables basic fallback styling. This works particularly well when you want to use a value that is quite new and not supported everywhere.
A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button's color when the user's pointer hovers over it.
In CSS the comma (,
) separates selectors. It's not a selector itself so it can't be used inside a selector. So depending of if you want to apply the rule to
.class1
and paragraphs that are not .class2
,.class1
nor class2
or .class1
and .class2
it's
p:not(.class1), p:not(.class2) {
}
or
p:not(.class1):not(.class2) {
}
or
p:not(.class1.class2) {
}
BTW, IMHO it's better to avoid :not
if possible and in this case, for example, have a general rule that applies to all p
s (with the properties you want to set in the :not
rule) and one that applies to ones with the class and overrides the properties of the first rule if necessary.
You can chain them (listing them didn't work for me either)...
p:not(.class1):not(.class2) {
...
}
jsFiddle.
Works for me in Chrome 10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With