admin管理员组文章数量:1399006
I'm actually trying to obtain the reverse effect of this: / I want my image to have a black overlay with some transparency, and when I hover with the mouse I'd like the overlay to dissapear.
Any thoughts please? Don't really care if it's css only or a bination between css and js.
Thanks
<div class="image">
<img src=".jpg" alt="" />
</div>
.image {
position:relative;
width:400px;
height:400px;
}
.image img {
width:100%;
vertical-align:top;
}
.image:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.4);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:hover:after {
opacity:1;
}
I'm actually trying to obtain the reverse effect of this: http://jsfiddle/4fgnd/ I want my image to have a black overlay with some transparency, and when I hover with the mouse I'd like the overlay to dissapear.
Any thoughts please? Don't really care if it's css only or a bination between css and js.
Thanks
<div class="image">
<img src="http://www.newyorker./online/blogs/photobooth/NASAEarth-01.jpg" alt="" />
</div>
.image {
position:relative;
width:400px;
height:400px;
}
.image img {
width:100%;
vertical-align:top;
}
.image:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.4);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:hover:after {
opacity:1;
}
Share
Improve this question
asked Oct 21, 2014 at 9:58
Andrei PAndrei P
3091 gold badge5 silver badges18 bronze badges
2
-
just swap the
opacity
s? – Rhumborl Commented Oct 21, 2014 at 10:00 - So just reverse the opacities? Set the opacity in :hover:after to 0, and the opacity in the starting class to 1. Or am I not understanding? – Calvin Scherle Commented Oct 21, 2014 at 10:00
2 Answers
Reset to default 4Here you go, simply reverse the css http://jsfiddle/4fgnd/1226/
.image:before {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:before {
opacity:1;
}
.image:hover:before {
opacity:0;
}
Switch opacity state in the css :)
Working example here http://jsfiddle/4fgnd/1225/
.image {
position:relative;
width:400px;
height:400px;
}
.image img {
width:100%;
vertical-align:top;
}
.image:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.6);
opacity:1;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.image:hover:after {
opacity:0;
}
本文标签: javascriptCSS Color overlay hoverStack Overflow
版权声明:本文标题:javascript - CSS Color overlay hover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744199001a2594877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论