0

I am trying to change properties of parent element when hover on child element. Here is my HTML

<div class="social-icons">          
    <div class = "innerSocialDiv">
        <a href="#" target="_blank" class="fa fa-facebook fa-lg" title="facebook"></a>
    </div>
</div>

I need to change a CSS property of innerSocialDiv when hovering on fa-facebook.

Here is what I did in my CSS:

.fa-facebook:hover  + .innerSocialDiv{
    background-color: black;
}

But it's not working.

Koby Douek
  • 14,709
  • 15
  • 58
  • 84
phpLover
  • 123
  • 1
  • 11
  • 1
    Possible duplicate of [Is there a CSS parent selector?](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – Mohammad Usman Mar 21 '17 at 05:30

4 Answers4

2

CSS always work left to right and top to bottom way. When you hover a child element then it's parent automatically called hover state.
Instead of this you can directly use following CSS

.innerSocialDiv:hover {
    background-color: black;
}
Super User
  • 8,642
  • 3
  • 24
  • 43
0

You don't need the + .innerSocialDiv, you can just use:

.fa-facebook:hover {
    background-color: black;
}
Koby Douek
  • 14,709
  • 15
  • 58
  • 84
0

Try this JQuery

$(".fa.fa-facebook").hover(function(){
    $(".innerSocialDiv").css("background-color", "black");
});
Carl Binalla
  • 5,153
  • 5
  • 25
  • 44
0

This is working code

.fa-facebook:hover .innerSocialDiv{
background-color: black;

}

Bhupinder kumar
  • 728
  • 4
  • 18