I have this html code
<article>
<div class="a">
<div class="a_b"></div>
</div>
<div class="c"></div>
</article>
I need to do some changes to div .c on div .a_b hover Can I do this using scss (or native css), without using any javascript code?
You can deploy the
:hoverpseudo-class (and other pseudo-classes like:focus,:checked,:targetetc.) to modify the styles on:In this setup:
You can apply a pseudo-element to
.aand it could modify the styles on.a(itself),.a_b(its child) or.c(its sibling).But a pseudo-element on either
.a_bor.ccan't modify the styles on any element except the element itself - because neither element has any children or any subsequent siblings.The solution:
In your structure, add
.a_bas a subsequent sibling of.a:and then use CSS positioning to re-position
.a_bso that visually, it appears to be inside.a(even though it is actually a sibling element of.a, rather than a child element of.a).