简体   繁体   English

使悬停和其他CSS细节上的图片变暗

[英]Darken picture on hover and other css details

Hello people from StackOverflow. 大家好,来自StackOverflow。 I'm trying to do something exactly like in this website: http://anayafilms.com/ (work section). 我正在尝试在此网站上做完全一样的事情: http : //anayafilms.com/ (工作部分)。 It's basically an image but on mouse over, it gets darken, a text at the bottom and two "buttons" (just some font awesome icons in a circle), along with some basic animation. 它基本上是一幅图像,但在鼠标悬停时会变暗,在底部显示一个文本,并在两个“按钮”(仅一个圆圈中显示一些字体真棒图标)以及一些基本动画。 So far I only have the image in a div and no idea on how to do that, so if anyone can help me out that'd be amazing. 到目前为止,我只将图片放在div中,却不知道该怎么做,所以如果有人可以帮助我,那就太好了。

Before and after, just to illustrate it in case you don't wanna go on the website 之前和之后,仅作说明,以防您不想访问网站

Depending on what you really need it to do, you might be able to do this without javascript. 根据您真正需要它执行的操作,您可能可以在不使用javascript的情况下执行此操作。 Here is an example that makes use of the css pseudo class :hover and some absolute positioning. 这是一个使用css伪类:hover和一些绝对定位的示例。 I'm darkening the background, which you can set as an image, by using a layer above it with a opacity: .5 black background created using background: rgba(0,0,0,.5) . 我通过使用opacity: .5的图层来使背景变暗,您可以将其设置为图像opacity: .5黑色背景,使用background: rgba(0,0,0,.5)

 .css-rollover { width: 300px; height: 200px; overflow: hidden; position: relative; } .css-rollover:hover .overlay { opacity: 1; pointer-events: all; } .bg { width: 100%; height: 100%; background: red; } .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.5); text-align: center; color: #fff; opacity: 0; pointer-events: 0; transition: opacity .2s; } .overlay p { position: absolute; bottom: 20px; left: 50%; transform: translateX( -50% ); } .overlay .fa-links { position: absolute; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); } .overlay .fa-links a { display: inline-block; width: 20px; height: 20px; line-height:20px; border-radius: 50%; margin: 5px; padding: 5px; background: blue; text-decoration: none; color: #fff; } 
 <div class="css-rollover"> <div class="bg" ></div> <div class="overlay"> <div class="fa-links"> <a href="#">A</a> <a href="#">B</a> </div> <p>You're hovering...</p></div> </div> 

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

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