Peter6528 Peter6528 - 1 month ago 10
CSS Question

CSS set divb color, when diva:hover

I want, when the first class hover, the second class's color is white.

<div class="diva">This is the first class</div>

<div class="divb">This is the second class</div>

<style>
.diva:hover .divb {
color:#fff;
}
</style


but, this isn't work. How can I do this?

Answer

"~" This operator known as (general sibling operator) can be used in your case for providing hover effect for another class. and below code make second class font color white .this operator can be used if classes are not in adjacent position

<html>
   <body>
      <div class="diva">This is the first class</div>
      <div class="divb">This is the second class</div>
      <style>
         .diva:hover ~ .divb {
         color:#fff;
         }
      </style>
</html>