Changing the style of one div when hovering over another

user8758206

I'm trying to figure out why the background of classes 'b' aren't changing when hovering over class 'a', as in this question. How can I get this to work? I'd also like it to work with the a tag.

Thanks for any help!

.a {
  width: 200px;
  height: 200px;
  background: orange;
}
.b {
  background: lightgreen;
}
.a:hover + .b {
    background: #ccc;
}
<div class='a'>
  <span class='b'>here</span>
  <span class='b'><a href='http://www.google.com'>here</a></span>
</div>

VXp

You are using the wrong selector, you should be using the direct child combinator or > instead since span's are inside the div:

.a {
  width: 200px;
  height: 200px;
  background: orange;
}
.b {
  background: lightgreen;
}
.a:hover > .b {
    background: #ccc;
}
<div class='a'>
  <span class='b'>here</span>
  <span class='b'><a href='http://www.google.com'>here</a></span>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Changing divs when hovering over a different div

How do add a class to another div, when hovering over one div?

jQuery hovering over one div to trigger changes in another div

Changing background of main div when hovering over subdiv

How to change the style of other elements when hovering over one of them?

How to display a div when hovering over another div

Change the Brightness of a div when hovering over another div

Changing CSS of one element when it's hovering another

How to change css of one class when hovering over another?

How to scroll up a div when hovering over another element

Color of the text not changing when hovering over a button

Hovering over one element changes another?

Hovering over image and displaying text in another div

Hovering over 1 div to change content in another

change css of one div by hovering on another div

Changing a div's style when clicked, and changing it back when another div is clicked

Displaying button when hovering over div in TailwindCSS

How can I change one svg path ID element when hovering over another element

Hovering one item to display the child in another div

How to make an element active on hover, and remain active when im hovering over another specific div

Affect another div when hovering CSS

Changing the attributes of the what appears when hovering over a Choropleth Map in plotly

Changing color of letters one by one in a html text when hovering

How to change the div style when you move the mouse over another element in another div?

While hovering over one element, disable hover on another

Make an element appear and make adjustments when hovering over another element

How to change color of element when hovering over another element?

When hovering over <ul> I want another <ul> to show up

WPF - hide element when hovering a mouse over another element