CSS is the parent design class if the child has a specific class

Possible duplicate:
Sophisticated CSS selector for parent of active child
Is there a parent CSS selector?

Is there a way to create a parent class based on if its children have a specific class?

<div class="container"> <div class="content1"> text </div> </div> 

.

 <div class="container"> <div class="content2"> text </div> </div> 

I want to create the first .container in a different way based on if the child class is content1 or content2 . This should be a purely css solution, without javascript.

+6
source share
3 answers

Why not use container1 + content and container2 + content ?

 <div class="container1"> <div class="content"> text </div> </div> <div class="container2"> <div class="content"> text </div> </div> 

And then write CSS like this:

 .container1 .content { /* Container 1 styles here */ } .container2 .content { /* Container 2 styles here */ } 
+5
source

No, you cannot do this. CSS cannot select elements based on their children, except to check if an element is empty or not.

+4
source

What you're asking for is a mythical CSS parent selector. Maybe someday.

+3
source

Source: https://habr.com/ru/post/927872/


All Articles