Otaku Kyon
Otaku Kyon

Reputation: 445

Changing the color of a child class inside a certain parent class

I want to change the color of class number3 for websites that have the class category as one of its parents. The only way I know to change the color would be:

.category > .number1 > .number2 > .number3 {color:purple;}

But I guess there is a better solution without naming every parent class of number3.

How can I change the color from green to purple using CSS without knowing the names of the parent classes, where one of them is class category?

.number1 {color:blue;}
.number2 {color:red;}
.number3 {color:green;}
.category {color:yellow;}
<div class="category">
        Text1
  <div class="number1">
  Text2
  <div class="number2">
    Text3
    <div class="number3">
      Text4
        </div>
      </div>
    </div>
  </div>

Upvotes: 0

Views: 120

Answers (1)

DACrosby
DACrosby

Reputation: 11450

You can simply name the parent and then the element you want to style

.category .number3 {color:purple;}

Upvotes: 4

Related Questions