我在我的主页(或index.html)上有图像,我希望能够将图像悬停在图像上,然后黑色图像以低透明度淡入淡出。黑色图像在图像上淡出
例如:http://wethepeoplebmx.de/hardgoods - 如果您将鼠标悬停在其中一幅图像(或产品)上,您可以看到我想要淡化的东西。我对HTML和CSS相当陌生,还有脚本和类似的东西。我假设它的东西做CSS,例如,悬停等提前
我在我的主页(或index.html)上有图像,我希望能够将图像悬停在图像上,然后黑色图像以低透明度淡入淡出。黑色图像在图像上淡出
例如:http://wethepeoplebmx.de/hardgoods - 如果您将鼠标悬停在其中一幅图像(或产品)上,您可以看到我想要淡化的东西。我对HTML和CSS相当陌生,还有脚本和类似的东西。我假设它的东西做CSS,例如,悬停等提前
谢谢我想你想是这样的 -
.wrap{position:relative;height: 100px;width: 120px;}
.wrap img{width: 100%;;height: 100%;}
.effect{background: rgba(0, 0, 0, .5);;position: absolute;height: 100%;width: 100%;;top:0;display: none;}
.wrap:hover .effect{display: block;opacity:.4}
<div class="wrap">
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcQiWGXo4U6CCvNItlDYFgEQz4d3T-YjLj13nqUZ-crpAr3qMPx-">
<div class="effect">
text
</div>
</div>
是的,是的!但是,不是黑色来临,是否有可能教我如何让它褪色? –
你想淡出图像或黑色? –
@JoshMurray检查我张贴的重复网址:http://stackoverflow.com/questions/21145621/css-transition-opacity-fade-background – Bram
你可以用CSS3动画和:hover
来做到这一点。
.wrap {
width: 100px;
height: 100px;
position: relative;
}
.effect {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: none;
/* First we need to help some browsers along for this to work.
Just because a vendor prefix is there, doesn't mean it will
work in a browser made by that vendor either, it's just for
future-proofing purposes I guess. */
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
/* ...and now for the proper property */
transition: .5s;
}
.effect:hover {
background: rgba(0, 0, 0, 0.4);
}
<div class="wrap">
<img src="http://placehold.it/100x100">
<div class="effect"></div>
</div>
显示你的代码的努力。 –
比onhover事件和一个大多透明(~20%或许不透明)更多的事情? –
这将是毫无意义的显示代码,因为我没有添加一个图像在另一个,我不太确定如何去做,这就是为什么我问这个问题;你能给我一些关于如何做到这一点的代码吗? –