I need to use CSS to apply style to class article ONLY if class subject is present inside .container
<div class="container">
<div class="subject">
...
</div>
<div class="article">
...
</div>
</div>
I was trying to use sibling selector, but it does not seem to work. What am I missing?
.container + .subject .article { ... }
The adjacent sibling combinator is meant for sibling elements. Your selector wasn't working because .container
and .subject
are not siblings, .subject
is a child of .container
.
.container .subject + .article
The elements .subject
and .article
are siblings, therefore it should work.
Example Here
You can use the sibling selector:
.container .subject + .article { // Your CSS rules
The rule you have now grabs the .container
, checks for the sibling .subject
, and then grabs the child .article
, so it's just in the wrong order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With