简体   繁体   English

将鼠标悬停在文本链接上时,不透明度会闪烁

[英]Opacity flickers when hovering over text link

I see this is a common problem, but the solutions I have borrowed from previous SO answers do not seem to work. 我看到这是一个普遍的问题,但是我从以前的SO答案中借用的解决方案似乎不起作用。 I have a series of image on my website, and when someone hovers over them, they display text (including a link) over the image, while reducing the opacity of the image. 我的网站上有一系列图像,当有人将鼠标悬停在其上时,它们会在图像上显示文本(包括链接),同时减少图像的不透明度。 The issue is, when someone hovers over the image, the hover on the image loses focus and the opacity begins to flicker. 问题是,当有人将鼠标悬停在图像上时,图像上的悬停会失去焦点,并且不透明度开始闪烁。 I've tried encapsulating the image and associated text in a div as suggested here: Hover-Effect disappears, when hovering over Text . 我尝试按照以下建议将图像和相关文本封装在div中:将鼠标悬停在Text上时,悬停效果消失 But that doesn't work in my case. 但这在我的情况下不起作用。

 .hover_img:hover img { opacity: .2; } .portfolio_img:hover + .center_text { display: block; } .center_text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: none; font-weight: bold; } 
 <div class="container"> <div class="row"> <div class="col-md-4"> <div class="hover_img"> <img class="portfolio_img" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Image"> <div class="center_text">Click here for info <a href="https://stackoverflow.com" target="_blank">Stackoverflow</a></div> </div> </div> </div> </div> 

It happens because .portfolio_img:hover gets confused when you hover over the text. 发生这种情况是因为将鼠标悬停在文本上时.portfolio_img:hover变得混乱。 Easy way to fix it is to change it to .hover_img:hover 修复它的简单方法是将其更改为.hover_img:hover

 .hover_img:hover img { opacity: .2; } .hover_img:hover .center_text { display: block; } .center_text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: none; font-weight: bold; } 
 <div class="container"> <div class="row"> <div class="col-md-4"> <div class="hover_img"> <img class="portfolio_img" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Image"> <div class="center_text">Click here for info <a href="https://stackoverflow.com" target="_blank">Stackoverflow</a></div> </div> </div> </div> </div> 

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

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