opacity: 0;
使得它不可见。当鼠标悬停时,内部 div 应该出现在我的图像上方。我已经实现了这一点,但现在我希望进一步改进它,通过让 '覆盖' div(以 0.5 的不透明度出现)���渐向下滑动到图像上。理论上我可以用 JavaScript 实现,但这次必须是纯 CSS 解决方案。到目前为止,我的解决方案只是让覆盖 div 逐渐出现(淡入),但没有像我从未在单独的 CSS 中做过的那样向下滑动。
请参见下面的图片以进一步了解:
HTML 代码:
<div class="img"> <img class="squareImg" src="img1.jpg"/><div class="overlay"> tweet This <br> Buy This</div></div>
<div class="img"> <img class="squareImg" src="img3.jpg"/></div>
<div class="img"> </img></div>
CSS(层叠样式表)
.overlay{
position: absolute;
width: 200px;
overflow-y: hidden;
transition-property: all;
transition-duration: .5s;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
height: 200px;
background-color: red;
border: 1px solid white;
top: 10px;
left: 10px;
opacity: 0;
} .overlay:hover{
cursor:pointer;
opacity: 0.5;
z-index: 1;
}
.img{
position: relative;
margin-bottom: 10px;
border: 2px solid yellow;
background-color: black;
width: 200px;
height: 200px;
left: 50%;
margin-left: -110px;
padding: 10px;
}