2

I understand the basic gist of using :not() in CSS, but it doesn't seem to work for me. I am trying to do something like:

input[type=text][readonly]:not(.class1, .class2) {
background-color: #DDDDDD;
color: #1E1E1E;
}

But this does nto seem to work for me. whenever I read any information on this, it will have examples like input:not(.class1, .class2) {, but nothing between the tag and the :not() part. Am I correct in assuming that the syntax I have written is incorrect? Can I not define the tag element any more if I use :not()?

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
user3334871
  • 1,251
  • 2
  • 14
  • 36

3 Answers3

2

Your only issue is that you're passing two selectors inside the :not() use only one per statement.

Currently extended arguments (foo, bar) are not supported by any browser.

Use

:not(.class1):not(.class2)

https://developer.mozilla.org/en-US/docs/Web/CSS/%3Anot

input[type=text][readonly]:not(.class1):not(.class2) {
  background-color: #DDDDDD;
  color: #1E1E1E;
}
<input type=text readonly class="class1">
<input type=text readonly>
<input type=text readonly class="class2">
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
2

:not accepts only simple selectors, and not lists of them.

So your selector should look like:

input[type=text][readonly]:not(.class1):not(.class2) {...}
c-smile
  • 26,734
  • 7
  • 59
  • 86
2

Use it combined way:

:not(.class1):not(.class2)

The :not selector is not a function. It is like any other selector taking in the other selector.

Your final CSS should be:

input[type=text][readonly]:not(.class1):not(.class2) {
  /* Styles */
}

Snippet

input[type=text][readonly]:not(.class1):not(.class2) {
  background-color: #DDDDDD;
  color: #1E1E1E;
}
<input type=text readonly class="class1">
<input type=text readonly class="class2">
<input type=text readonly>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252