0

codepen

div:not(.wayne) div:not(.garth) .content {
  background-color:red;
}

 

<div class="wayne">
  <div class="content">Party On Garth</div>
</div>

<div class="garth">
  <div class="content">Party On Wayne</div>
</div>

<div class="Saitama">
  <div class="content">One punch.</div>
</div>

<div class="Naruto">
  <div class="content">Dattebayo</div>
</div>

The background should be red unless the class is either .garth or .wayne. How can I do this for all .content?

Saitama and Naruto should have red backgrounds. Right now nothing has a red background. Any similarly added new characters should also have a red background.

Pseudocode if(!(wayne || garth)){ apply red background to .content}

I'm willing to use JavaScript if necessary. I prefer css.

2

3 Answers 3

3

Chain the :not together

div:not(.wayne):not(.garth) .content {
  background-color:red;
}
<div class="wayne">
  <div class="content">Party On Garth</div>
</div>

<div class="garth">
  <div class="content">Party On Wayne</div>
</div>

<div class="Saitama">
  <div class="content">One punch.</div>
</div>

<div class="Naruto">
  <div class="content">Dattebayo</div>
</div>

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

Comments

1

If you want to have multiple :not selectors, you need to change your CSS to look like this

CSS

div:not(.wayne):not(.garth) .content {
  background-color:red;
}

CodePen

Comments

0

You are using a descendant combinator: . Your selector means:

"Select each element with class content which is a descendant of any div element without garth class which is a descendant of any div element without wayne class."

Remove it.

div:not(.wayne):not(.garth) > .content {
  background-color:red;
}

"Select each element with class content which is a child of a div element without garth nor wayne classes."

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.