简体   繁体   中英

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.

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> 

see here jsfiddle

transition doesn't work with visibility . it only works with 'calulable' values like (0,1) and so...instead of visibility use opacity

code :

bio_overlay {
  background: #ffc27f;
  bottom: 0;
  height: 100%;
  left: 2.5rem;

  position: absolute;
  right: 0;
  top: 0;
  transition: opacity 0.5s ease-in-out 0s;
  opacity:0;
  width: 100%;
}

.image_container:hover  .bio_overlay {
    opacity:0.4;
}

Just replace the visibility: tags with opacity: tags. https://jsfiddle.net/r4LLf4w0/2/

try this:

.image_container:hover  .bio_overlay {
visibility: visible;
opacity: 0.5;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM