简体   繁体   English

CSS Hover:悬停时叠加在图像上

[英]CSS Hover : Overlay on image while hovering

I have an image.我有一个图像。 onhover the image is changing as well as border-radius is disappearing.悬停图像正在改变以及边界半径正在消失。 but along with it I want an overlay background on the image.但随之而来的是我想要在图像上叠加背景。

I have tried this code.我试过这个代码。

 .team-member { text-align: center; margin-bottom: 50px; } .opacity_box{ width: 225px; height: 225px; background: rgba(0,0,0,0.6); display: none; position: absolute; left: 27.5%; top: 0; } .team-member img { margin: 0 auto; -webkit-transition: all .3s; -moz-transition: all .3s; transition: all .3s } .team-member img:hover { border-radius:0%; -webkit-transition: all .3s; -moz-transition: all .3s; transition: all .3s; } .team-member img:hover + .opacity_box { display: block; }
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <div class="team-member"> <img src="https://blackrockdigital.github.io/startbootstrap-agency/img/team/1.jpg" onmouseout="this.src='https://blackrockdigital.github.io/startbootstrap-agency/img/team/1.jpg'" onmouseover="this.src='https://blackrockdigital.github.io/startbootstrap-agency/img/team/2.jpg'" class="img-responsive img-circle" alt=""> <div class="opacity_box"></div> <h4>Kay Garland</h4> <p class="text-muted">Lead Designer</p> <ul class="list-inline social-buttons"> <li><a href="#"><i class="fa fa-twitter"></i></a> </li> <li><a href="#"><i class="fa fa-facebook"></i></a> </li> <li><a href="#"><i class="fa fa-linkedin"></i></a> </li> </ul> </div>

I get the overlay effect but it is not working properly.我得到了叠加效果,但它无法正常工作。

Thank you.谢谢你。

Problem: when you show overlay, you are no longer hovering image.问题:当您显示叠加层时,您不再悬停图像。

Solution: Apply hover effects when you hover parent, not image itself解决方案:在您悬停父级时应用悬停效果,而不是图像本身

 .team-member { margin-bottom: 50px; text-align: center; } .opacity_box { width: 100%; /* usually you want to have overlay cover area, so no need for fixed size */ height: 100%; background: rgba(0, 0, 0, 0.6); display: none; position: absolute; left: 0; top: 0; pointer-events: none; /* click-through overlay */ } .image-wrapper img { margin: 0 auto; -webkit-transition: all 300ms; -moz-transition: all 300ms; transition: all 300ms; } .image-wrapper:hover img { border-radius: 0%; -webkit-transition: all 300ms; -moz-transition: all 300ms; transition: all 300ms; } .image-wrapper:hover .opacity_box { display: block; } .image-wrapper { position: relative; display: inline-block; }
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <div class="team-member"> <div class="image-wrapper"> <img src="https://blackrockdigital.github.io/startbootstrap-agency/img/team/1.jpg" onmouseout="this.src='https://blackrockdigital.github.io/startbootstrap-agency/img/team/1.jpg'" onmouseover="this.src='https://blackrockdigital.github.io/startbootstrap-agency/img/team/2.jpg'" class="img-responsive img-circle" alt=""> <div class="opacity_box"></div> </div> <h4>Kay Garland</h4> <p class="text-muted">Lead Designer</p> <ul class="list-inline social-buttons"> <li><a href="#"><i class="fa fa-twitter"></i></a> </li> <li><a href="#"><i class="fa fa-facebook"></i></a> </li> <li><a href="#"><i class="fa fa-linkedin"></i></a> </li> </ul> </div>

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

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