-1

Is there a way to apply style on the parent selector based on the class specified in the child. I know this can be done in Javascript but I am trying to find a solution which can be applied on my css file. I tried:

div < .active {
    background:red;
}

but it selects/applies style only the child. I want the style to be applicable on the div parent here for example.

Any suggestions on this?

Thanks in advance.

Suraj Nair
  • 456
  • 1
  • 6
  • 23

2 Answers2

2

There is No parent selector in CSS as of today. So the answer is No you cannot do it in CSS.. JavaScript is the only option

Rajshekar Reddy
  • 17,202
  • 3
  • 34
  • 54
-1

Try:

div > .active {
    background:red;
}

it is better to mention element also such as

div > div.active {
    background:red;
}
w.Bala
  • 129
  • 3