2

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.

Community
  • 1
  • 1
user5854440
  • 271
  • 4
  • 14

3 Answers3

3

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

user5854440
  • 271
  • 4
  • 14
1

You would do something like this:

SASS

#a {
  #b p:hover {
    color: red;
  }
}

CodePen

Hunter Turner
  • 6,804
  • 11
  • 41
  • 56
0

My 2 cents if someone ends up here for a similar but not exactly the same issue

I was trying to affect the span inside a div when hover applies:

.my-container {

  &:hover {
    color: red; // whatever
      > span {  /* the first span child */
        opacity: 1;
        background-color: blue;
    }
  }

}
Manu Artero
  • 9,238
  • 6
  • 58
  • 73