I have two adjacent selectors that I would like to effect when hovering over the other. In the example below, the two selectors should effect the others CSS when hovered. This works perfectly when hovering .a
, but not when hovering .b
. I realize this is because the DOM is read in order, and therefore CSS selectors cannot work backwards.
However, is there a jQuery workaround (or any other suggestions) that can achieve this effect?
Here is a Fiddle
Thanks.
HTML
<figure>
<div class="a">
A
</div>
<div class="b">
B
</div>
</figure>
CSS
.a {
width: 100px;
height: 100px;
background: red;
}
.b {
width: 100px;
height: 100px;
background: blue;
}
.a:hover ~ .b {
background: green;
}
.b:hover ~ .a { /* This one doesn't work */
background: green;
}