4

I would like to stack more than one class in not() selector but ,;: does not work.

input[type=text]:hover:not(.ui-pg-input .mandatory){ background-color: #D9EDF7;}

So, what is proper way to stack classes in css not() selector?

2 Answers 2

4

Two syntactic alternatives:

  1. use two classes in one :not operator:

input[type=text]:hover:not(.ui-pg-input.mandatory){background-color: #D9EDF7;}

(note the removed blank between the classes)

  1. use the :not operator twice:

input[type=text]:hover:not(.ui-pg-input):not(.mandatory){background-color: #D9EDF7;}

Note however that both have different meaning: the first uses an or operator, so it matches all elements not having both classes (so having none or one), whilst the second uses an and operator, thus matching all elements not having one or the other class (so having none). So it depends on what you want to do...

Sign up to request clarification or add additional context in comments.

1 Comment

a note - I don't think #1 works, even though it seems like it should. I am still trying to figure out how to do exactly what this answer suggests #1 does (apply a rule if element has neither class a nor class b, or only one of them, but not both), See here for an example: jsfiddle.net/9jhu0qc5/1 - if this worked you would expect the first 2 boxes to have a black border, but not so.
2

You can use twonot() to do this example:

p:not(.class_one):not(.class_two){

p:not(.one):not(.two){
  color:red;
  }
<p class="one">Text</p>
<p class="two">Text</p>
<p class="three">Text</p>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.