简体   繁体   English

位置:绝对“背景”图像Internet Explorer问题

[英]position:absolute “background” image Internet Explorer issue

I have 3 images. 我有3张图片。 When hovering one an image goes on top of the hovered one. 当悬停一个图像时,会在悬停的图像上方移动。

Here's my code: HTML 这是我的代码:HTML

<a class="toggle"><img src="" style="position:absolute"><img src=""></a>
<a class="toggle" style="margin-left:30px;margin-right:30px"><img src="" style="position:absolute"><img src=""></a>
<a class="toggle"><img src="" style="position:absolute"><img src=""></a>

CSS CSS

a.toggle img:hover {
    opacity:0.1;
    filter:alpha(opacity=10); /* For IE8 and earlier */
}

Everything works fine with Firefox and Chrome.. Problem is with Internet Explorer (also IE 10). Firefox和Chrome一切正常。问题出在Internet Explorer(也是IE 10)上。 The middle image is positioned weirdly! 中间的图像很奇怪!

Check out the fiddle with IE to see the problem http://jsfiddle.net/6nebL/ 看看IE的小提琴,看看问题http://jsfiddle.net/6nebL/

How can I fix this in a clean way and without adding complexity to the code? 如何以干净的方式解决这个问题并且不增加代码的复杂性?

set a to inline-block : 设置ainline-block

a {
    display: inline-block;
}

fiddle updated: http://jsfiddle.net/6nebL/3/ 小提琴更新: http//jsfiddle.net/6nebL/3/

Here, I've updated your CSS and HTML to be a bit more ... friendly. 在这里,我已经更新了你的CSS和HTML,以便更友好。 The CSS: CSS:

.toggle img:hover {
    opacity:0.1;
    filter:alpha(opacity=10); /* For IE8 and earlier */
}

.toggle {
    display:inline-block;
    vertical-align:middle;
    width:150px;
    position:relative;
    margin:0 30px;
}

img {
    position:absolute;
    top:0;
    left:0;
}

And HTML is just without the inline styles. HTML没有内联样式。

Here is the updated jsFiddle. 这是更新的jsFiddle。

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

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