CSS selector for classless

I use a selector to select all elements that do not have one class:

.list th:not(.foo) { /* some rules */ } 

How can I apply this to multiple classes?

 .list th:not(.foo), .list th:not(.bar) { /* some rules */ } 

The CSS above will certainly not do this, I need something like this pseudo:

 .list th:not(.foo and .bar) 

Is this possible in CSS and how?

+5
source share
4 answers

You can use as many selectors as possible :not() .

 :not(.foo):not(.bar) 
+2
source

With upcoming CSS4 selectors, you can use syntax like:

 :not(.class1, .class2, .class3) 

etc. But browser support is not very good so far. To use it today, you can use cssnext .

+2
source
 .list th:not[class*="class"] { } 

It will work with all classes such as class1, class2, etc.

0
source

Using a comma to separate a class name may make you want

 .list th:not(.class1, .class2) 
0
source

Source: https://habr.com/ru/post/1257513/


All Articles