Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 :not negation pseudo-class not fully supported by Firefox?

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?

like image 508
Camsoft Avatar asked Mar 21 '11 14:03

Camsoft


People also ask

Which is not a CSS pseudo-class?

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.

What happens when browser does not understand CSS?

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.

Which is a CSS pseudo-class?

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.


2 Answers

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

  • paragraphs that are not .class1 and paragraphs that are not .class2,
  • paragraphs that have neither .class1 nor class2 or
  • paragraphs that don't have .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 ps (with the properties you want to set in the :notrule) and one that applies to ones with the class and overrides the properties of the first rule if necessary.

like image 114
RoToRa Avatar answered Nov 15 '22 08:11

RoToRa


You can chain them (listing them didn't work for me either)...

p:not(.class1):not(.class2) {
  ...  
}

jsFiddle.

Works for me in Chrome 10.

like image 32
alex Avatar answered Nov 15 '22 08:11

alex