2

HTML:

<div class="container">
  <div class="parent">one
    <div class="child">two</div>
  </div>
</div>

CSS:

.parent {
  background: red;
  height: 200px;
  width: 200px;
}
.child {
  background: green;
  height: 100px;
  width: 100px;
  margin-top: 50px;
  margin-left: 50px;
}
/* insted of apply individual */
/* .parent:hover {
     background: blue;
} 
  .child:hover {
    background: black;
  } 
*/

I want to change both parent and child background colours. when hover on parent(parent bg:blue, child bg:black). Here the problem is parent & child have the same property(background) but both have different background colours. how can I apply them simultaneously?

Manas Khandelwal
  • 3,006
  • 2
  • 8
  • 18
Manu
  • 23
  • 3

1 Answers1

1

You can change child hover color using this: .parent:hover .child

.parent {
  background: red;
  height: 200px;
  width: 200px;
}
.child {
  background: green;
  height: 100px;
  width: 100px;
  margin-top: 50px;
  margin-left: 50px;
}
/* insted of apply individual */
 .parent:hover {
  background: blue;
} 
.parent:hover .child {
  background: black;
} 
<div class="container">
  <div class="parent">one
    <div class="child">two</div>
  </div>
</div>
Minal Chauhan
  • 5,739
  • 5
  • 15
  • 36