Raj Raj - 4 months ago 9
HTML Question

Smooth CSS transition on hover over a div

I have the following code but can't make the smooth transition working on hover.

<div class="image_container">
<figure><img alt="" src="http://dummyimage.com/279x279/000000/fff"></figure>
<div class="bio_overlay"></div>
</div>


I applied transition effect on actual class but for some reason it is not detecting the effect.

Demo : https://jsfiddle.net/squidraj/r4LLf4w0/

Any help is highly appreciated.

Answer

You are using visibility and transitioning opacity. The properties visibility, display and a few more cannot be transitioned.

.image_container {
  position: relative;
  width: 279px;
  height: 279px;
}
.image_container img {
  display: block;
  position: relative;
}
.bio_overlay {
  background: #ffc27f;
  bottom: 0;
  height: 100%;
  left: 2.5rem;
  opacity: 0.4;
  position: absolute;
  right: 0;
  top: 0;
  transition: opacity 0.5s ease-in-out 0s;
  width: 100%;
  opacity: 0;
}
.image_container:hover .bio_overlay {
  opacity: 0.4;
}
<div class="image_container">
  <figure>
    <img alt="" src="http://dummyimage.com/279x279/000000/fff" />
  </figure>
  <div class="bio_overlay"></div>
</div>