Reputation: 977
I'm trying to change the div color by hovering over an anchor tag but when I am but nothing is happening, here is my code below and jsfiddel link https://jsfiddle.net/rhulkashyap/udvzanqz/.
HTML & CSS
.hover-me{
margin-bottom:50px;
display:block;
}
.change{
width:200px;
height:200px;
background:#00ACC1;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
font-size:20px;
color:#fff;
}
.hover-me:hover .change{
background:#00796B;
}
<a href="#" class="hover-me">Change Div color by hovering me</a>
<div class="change">Hello Universe</div>
Upvotes: 2
Views: 66
Reputation: 162
This is working perfectly however you want:
.hover-me:hover + .change{
background:#00796B;
}
here is working jsFiddle demo : https://jsfiddle.net/udvzanqz/2/
Upvotes: 3
Reputation: 1712
Just change your css as following :-
.hover-me:hover+.change{
background:#00796B;
}
It may help you.
Upvotes: 1
Reputation: 122047
You need to use sibling selector
.hover-me{
margin-bottom:50px;
display:block;
}
.change{
width:200px;
height:200px;
background:#00ACC1;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
font-size:20px;
color:#fff;
}
.hover-me:hover ~ .change{
background:#00796B;
}
<a href="#" class="hover-me">Change Div color by hovering me</a>
<div class="change">Hello Universe</div>
Upvotes: 5