I've searched for hours but can't seem to figure out how to target an element that occurs behind another, rather than in front of.
The css + selector targets an element in front of another.
Example:
HTML:
<div class="apples"></div>
<div class="bananas"></div>
CSS:
.apples + .bananas {
background-color: blue;
}
This will turn the bananas class blue but I want to be able to target the apples class using the bananas class. Seems like the adjacent sibling combinator can't accomplish this. This seems like a mind-bogglingly simple thing to do but there doesn't seem to be an answer for this online. Any help?
What I've tried: I tried using the adjacent sibling combinator and swapping around the target and the base element but this doesn't work:
HTML:
<div class="apples"></div>
<div class="bananas"></div>
CSS:
.bananas + .apples {
background-color: blue;
}
I'm trying to only add style to an adjacent element that occurs directly before another element based on what classes exist in the the base element. So I only want to add styling to the elements that contain the apples class based on whatever other classes exist in elements that contain the bananas class.