Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth CSS transition on hover over a div

Tags:

html

css

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.

like image 852
Raj Avatar asked Dec 14 '22 05:12

Raj


1 Answers

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>
like image 155
Praveen Kumar Purushothaman Avatar answered Dec 30 '22 09:12

Praveen Kumar Purushothaman