Search code examples
htmlsass

sass: effect another element when another div is hovered


This question has been answered in CSS here, but I haven't been able to find an answer to it in sass. I'm trying to effect a div inside of another div whenever the outer div is hovered.

For example:

<div id="a">
   <div id="b">
      <p>Hello!</p>
   </div>
</div>

In sass, I would want to target div b's p tag and change it to a different color whenever div a is hovered over. Is this possible in sass? right now all I have is this:

#a{
   &:hover{
   //code to effect div b
   }
}

All help is appreciated.


Solution

  • Here's what I found worked:

    #a{
       //original color
       #b{
          p{
             color: red;
          }
       }
    
       //after hover
       &:hover{
          #b{
             p{
                color: green;
             }
          }
       }
    }
    

    Thank you to @HunterTurner for leading me in the right direction