Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector for not having classes

Tags:

css

I am using selector to select all elements not having one class:

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

How can I apply this to more than one class?

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

The CSS above will not of course do that, I need something like this pseudo:

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

Is it possible in CSS and how?

like image 526
Legionar Avatar asked Sep 30 '16 10:09

Legionar


People also ask

How do you select an element without a class?

The :not CSS pseudo-class can be used to select elements that do not contain a specific class, id, attribute etc.

Is () CSS pseudo-class?

The :is() CSS pseudo-class function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. This is useful for writing large selectors in a more compact form.


2 Answers

You can use as many :not() selectors as you like.

:not(.foo):not(.bar)
like image 111
Quentin Avatar answered Oct 26 '22 00:10

Quentin


With upcoming CSS4 selectors you can use a syntax like:

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

and so on. But browser support isn't good so far. To be able to use it today, you can use cssnext for example.

like image 43
Christoph Avatar answered Oct 25 '22 23:10

Christoph