简体   繁体   English

在CSS3缓入过渡中的:hover上显示Div叠加

[英]Display Div Overlay on :hover with CSS3 Ease-In Transitions

I've got the overlay working on :hover. 我已经覆盖工作:hover。 However I'd like to add an ease-in transition using CSS3. 但是我想使用CSS3添加一个轻松过渡。 Can't seem to find a working version online. 似乎无法在线找到有效版本。

To the code! 给代码!

So I have a div which contains just an image. 所以我有一个仅包含图像的div。 When I hover over it, it displays a coloured overlay with 2 text elements. 当我将鼠标悬停在其上时,它将显示带有2个文本元素的彩色叠加层。

<div class="item">
     <img src="assets/images/blah.jpg" class="image">
         <a class="overlay" href="#">
            <h3 class="title">Some title</h3>
            <div class="description">
              <h4>Lorem ipsum dolor sit amet. consectetur adipisicing elit.</h4>
            </div>
         </a>
</div>

For my CSS, I have added the -transition code: 对于我的CSS,我添加了-transition代码:

.item {
  position: relative;
  background-color: white;
  -webkit-transition: background-color 2s ease-in; 
  transition: background-color 2s ease-in; 
}

.overlay {
  background: white;
  position: absolute;
  display: none;
 }

.item:hover .overlay{
   display:block;
   background-color: black;
}

However this transition effect it isn't working! 但是此过渡效果不起作用! Please help! 请帮忙!

Do I need to change the -transition to use display or all ? 我需要将-transition更改为使用display还是all

I have a jsfiddle which has the :hover working , just without the animation. 我有一个jsfiddle,它具有:hover working ,只是没有动画。

Much appreciated 非常感激

Link: https://jsfiddle.net/jonahmclachlan/nwhzLu1g/2/ 链接: https//jsfiddle.net/jonahmclachlan/nwhzLu1g/2/

You must to change the display with an opacity for example, and add the transition to the overlay, not the item. 例如,您必须使用不透明度更改显示,并将过渡添加到叠加层,而不是项目。

See it working: 看到它的工作:

 .item { position: relative; background-color: white; } .overlay { background: white; position: absolute; opacity: 0; -webkit-transition: background-color 2s ease-in, opacity 2s ease-in; transition: background-color 2s ease-in, opacity 2s ease-in; } .item:hover .overlay{ background-color: black; opacity: 1; -webkit-transition: background-color 2s ease-in, opacity 2s ease-in; transition: background-color 2s ease-in, opacity 2s ease-in; } 
 <div class="item"> <img src="assets/images/blah.jpg" class="image"> <a class="overlay" href="#"> <h3 class="title">Some title</h3> <div class="description"> <h4>Lorem ipsum dolor sit amet. consectetur adipisicing elit.</h4> </div> </a> </div> 

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

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