I want to change the child div image opacity when the parent div is hovered. How to do this in CSS?
<div class="parent">
<div class="child">
<img src="" alt="" height="" width="">
</div>
</div>
I want to change the child div image opacity when the parent div is hovered. How to do this in CSS?
<div class="parent">
<div class="child">
<img src="" alt="" height="" width="">
</div>
</div>
Use :hover-selector and change the img opacity:
.child:hover img {
opacity: 0.8;
}
Or if you want to change opacity of the while child div then:
.parent:hover .child {
opacity: 0.8;
}
Sample Fiddle Link - JsFiddle
.parent {
width: 300px;
height: 300px;
background: red
}
.child {
width: 100px;
height: 100px;
background: green
}
.parent:hover .child {
opacity: .5
}
You can do something like this:
.parent {
background: red;
padding: 30px;
}
.parent:hover .child {
opacity: 0.3
}
.child {
background: blue;
padding: 30px;
}
<div class="parent">
<div class="child">
<img src="" alt="" height="" width="">
</div>
</div>