How could I use the :has
selector to style a sibling?
In this example, the logic is:
If the parent has a child with the class child1, child2 should be green.
but I can't seem to get it working- nor any :has
selector for that matter, but sources online give conflicting syntaxs. I'm confused by it.
.parent {
height: 100px;
width: 200px;
font-size: 10px;
}
.child1, .child2 {
width: 100px;
height: 50px;
background-color: red;
border: 2px solid black;
}
.child1 {
background-color: green
}
.parent:has(.child1) > .child2 {
background-color: green;
}
<div class="parent">
<div class="child1">
this is child1
</div>
<div class="child2">
this is child2
</div>
</div>