简体   繁体   English

Img在改变不透明度时移动:悬停

[英]Img moves when changing opacity on :hover

So I have a div with an image inside it that I want to start out at 0.7 opacity and change to 1 on hover but I am encountering an apparent bug where the image either moves 1px or gets 1px smaller (I can't tell for sure which) when I change the opacity on hover. 所以我有一个内部带有图像的div,我希望从0.7不透明度开始,并在悬停时更改为1,但我遇到一个明显的错误,图像要么移动1px要么变小1px(我无法确定当我在悬停时改变不透明度时。
This is apparently a known bug but none of the fixes in the other questions have worked for me. 这显然是一个已知的错误,但其他问题中的修复都没有对我有用。 I have tried setting backface-visibility: hidden; 我试过设置背面可见性:隐藏; and doing a transform but the bug remains. 并进行转换,但错误仍然存​​在。

Are there any new solutions to this bug? 这个bug有什么新的解决方案吗?

.collapse img { 
    width: 100%;
    margin-top: -90px; 
    margin-left: 75px;
    opacity: 0.7; 
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-transform: translateZ(0) scale(1.0, 1.0);
    border:none;
} 
.collapse:hover img {
    width: 100%; 
    opacity: 1;
    -webkit-backface-visibility: hidden;
    -webkit-transform: translateZ(0) scale(1.0, 1.0); 
    border:none;
}

Thanks, Adam 谢谢,亚当

EDIT - JS Fiddle - http://jsfiddle.net/wfe70gd1/6/ 编辑 - JS小提琴 - http://jsfiddle.net/wfe70gd1/6/

Live example can be seen here (right column below the charts) -- http://mmdoc.ajhtestserver.com/decks/1/ 这里可以看到实例(图表右下方) - http://mmdoc.ajhtestserver.com/decks/1/

Also it only appears to be happening in Firefox 它似乎只在Firefox中发生

You want to add the backface-visibility selector to your parent class (.collapse). 您希望将背面可见性选择器添加到父类(.collapse)。 You also need to include the Mozilla version of the selector. 您还需要包含选择器的Mozilla版本。 Wouldn't hurt to include Opera, too. 包括Opera在内也不会受到伤害。

-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1.0, 1.0);

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

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