简体   繁体   English

悬停在div上时平滑的CSS转换

[英]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/ 演示: https//jsfiddle.net/squidraj/r4LLf4w0/

Any help is highly appreciated. 任何帮助都非常感谢。

You are using visibility and transitioning opacity . 您正在使用visibility和过渡opacity The properties visibility , display and a few more cannot be transitioned. 属性visibilitydisplay和一些不能转换。

 .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 看到这里jsfiddle

transition doesn't work with visibility . transition不适用于visibility it only works with 'calulable' values like (0,1) and so...instead of visibility use opacity 它只适用于像'(0,1)这样的'calulable'值,所以...而不是可见性使用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. 只需使用opacity:标记替换visibility: opacity:标记。 https://jsfiddle.net/r4LLf4w0/2/ https://jsfiddle.net/r4LLf4w0/2/

try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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