0

I've done this, this , and this but gives me no luck. I'm trying to change the color of a div when the lower element is being hovered but I can't do it. I have this HTML structure like so:

  <div class="ms-parent">
      <button type="button" class="ms-choice"></button>
      <div class="ms-drop"></div>
  </div>

Here is what I've tried so far:

  .ms-parent:hover,
  .ms-choice:hover + .ms-drop,
  .ms-drop:hover,
  .ms-choice:hover,
  .ms-drop:hover ~ .ms-choice{ color:#000000!important; background: #ffffff; }

So when .ms-drop is being hovered I want .ms-choice to change its style. What I'm missing here?

Community
  • 1
  • 1
user3093453
  • 699
  • 2
  • 7
  • 24

1 Answers1

0

There is no Upper/previous element selector in CSS. You can select next immediate sibling element using + and you can select all the next siblings element using ~.

Kindly note it down, I mentioned next, because there is no previous selectors right now. Hopefully that will introduce on CSS4. You can use jquery to achieve this. Otherwise if you want to do it in CSS, you need to change the HTML structure like below.

 <div class="ms-parent">
  <div class="ms-drop"></div>
  <button type="button" class="ms-choice"></button>      
 </div>

Now you can target it like below.

 .ms-drop:hover ~ .ms-choice{ color:#000000!important; background: #ffffff; }   

Or

 .ms-drop:hover + .ms-choice{ color:#000000!important; background: #ffffff; }  

DEMO

Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54