arman
arman

Reputation: 31

background color not changing in css

:hover does not work. The background of div is not changing when hovering on a

Code:

a:hover div {
  background-color: yellow;
}
<a href="#">b</a>
<div>c</div>

Upvotes: 0

Views: 125

Answers (1)

Deepak Kumar T P
Deepak Kumar T P

Reputation: 1076

You can use + css selectore to select sibling of a.

Check this out for more child and sibling selectors : https://css-tricks.com/child-and-sibling-selectors/

Your code selects the child element. You should select the next sibling:

a:hover+div {
  background-color: yellow;
}
<a href="#">b</a>
<div>c</div>

Upvotes: 5

Related Questions