在 IE8、IE7 和可能的 IE6 中获取图像幻灯片前面的无序列表
我有一个简单的(绝对定位的)图像幻灯片,其中包含一些每隔几秒钟旋转一次的图像。
为了使变化图像的不同区域可点击,我还有一个包含不同链接的无序列表,相对定位以便使用 z-index。
这在 Firefox (3.6)、Safari (windows) 和 Chrome (windows) 中运行良好。然而,在 IE8 和 IE7 中,链接似乎消失在图像后面(我什至还没有在 IE6 中尝试过......)。
如何在 IE 中将无序列表置于最前面?(参见下面的代码)
编辑: 链接到工作页面
编辑 2: 我使用开发人员工具找到了什么IE8,当我删除时,链接可以工作并且位于幻灯片的顶部:
.links a { display: block; }
删除 display:block 的结果是我有 5 个微小的可点击区域覆盖了上部的图像左角。当我再次添加它时,图像上的任何地方都没有可点击的区域,尽管开发人员工具显示了链接应位于正确位置的方块。
代码(我没有包含JavaScript,因为它只对不透明度进行动画处理并添加/删除下面提到的类):
html
<div id="slideshow">
<ul>
<li><img src="/images/header01.jpg" alt="some_image" /></li>
<li><img src="/images/header02.jpg" alt="some_image" /></li>
<li><img src="/images/header03.jpg" alt="some_image" /></li>
</ul>
</div>
<ul class="links">
<li><a href="link1.html"> </a></li>
<li><a href="link2.html"> </a></li>
<li><a href="link3.html"> </a></li>
<li><a href="link4.html"> </a></li>
<li><a href="link5.html"> </a></li>
</ul>
css
ul.links {
z-index: 9999;
position: relative;
}
.links li {
float: left;
}
.links a {
display: block;
width: 192px;
height: 210px;
}
#slideshow {
position: absolute;
left: 0;
top: 0;
}
#slideshow li {
position: absolute;
top: 0;
left: 0;
z-index: 8;
opacity: 0.0;
border: none;
/* ie bugs */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
#slideshow li.active {
z-index: 10;
opacity: 1.0;
}
#slideshow li.last-active {
z-index: 9;
}
I have a simple (absolutely positioned) image slide-show that consists of a few images that rotate every few seconds.
To have different areas of the changing image click-able, I also have an unordered list containing the different links, relatively positioned in order to use z-index.
This works just fine in Firefox (3.6), Safari (windows) and Chrome (windows). However, the links seem to disappear behind the images in IE8 and IE7 (I haven´t even tried it in IE6 yet...).
How can I bring the unordered list to the front in IE? (see code below)
Edit: Link to working page
Edit 2: What I did find using the developers tools of IE8, is that the links work and are on top of the slide-show when I remove:
.links a { display: block; }
The result of removing display:block is that I have 5 tiny click-able areas overlaying the image in the upper left corner. As soon as I add it again there is no click-able area anywhere on the image although the developers tools show the squares where the links should be at the correct locations.
The code (I haven´t included the javascript as it only animates opacity and adds / removes the below mentioned classes):
html
<div id="slideshow">
<ul>
<li><img src="/images/header01.jpg" alt="some_image" /></li>
<li><img src="/images/header02.jpg" alt="some_image" /></li>
<li><img src="/images/header03.jpg" alt="some_image" /></li>
</ul>
</div>
<ul class="links">
<li><a href="link1.html"> </a></li>
<li><a href="link2.html"> </a></li>
<li><a href="link3.html"> </a></li>
<li><a href="link4.html"> </a></li>
<li><a href="link5.html"> </a></li>
</ul>
css
ul.links {
z-index: 9999;
position: relative;
}
.links li {
float: left;
}
.links a {
display: block;
width: 192px;
height: 210px;
}
#slideshow {
position: absolute;
left: 0;
top: 0;
}
#slideshow li {
position: absolute;
top: 0;
left: 0;
z-index: 8;
opacity: 0.0;
border: none;
/* ie bugs */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
#slideshow li.active {
z-index: 10;
opacity: 1.0;
}
#slideshow li.last-active {
z-index: 9;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,这就是你的问题!
IE 的 Javascript 解释器非常挑剔,当你像现在这样操作一个对象时,它通常会猛烈攻击。这将是其中之一。我猜问题是您正在更改对象,因此它认为该对象具有优先级。
就我个人而言,我只是简单地更改您的架构代码如下(pseduocode)。
从这里你所要做的就是简单地为每个图像设置一个类/ID名称,这样它们就可以在Javascript中轻松更改(这将是我理想的解决方案)
希望这会有所帮助,
[编辑]
仔细查看后在你的网站上我发现了一些问题:
CSS:
它不会影响这个,但需要修复。
现在,分解一些 CSS,IE 的问题是,由于某种原因,它不允许在 .active 类上使用链接。
如果您想了解我所描述的内容,只需使用 float: left; #image_bar .links LI 的关闭
您将看到所有链接都与中心对齐,并且它们位于不同的行上。所以这表明 IE 中存在定位问题。
现在要弄清楚如何解决这个问题。
现在只需向容器 #image_bar UL.links 添加宽度即可解决此问题
宽度需要为 962,就像您的最大宽度一样。
这将使它们的链接正确排列,而不是在单独的行上。
现在存在使它们出现在 IE 中图像顶部的问题。我将所有链接变成黑色,以便我能够看到它们,这使它们到达顶部并且可以点击。目前,我不确定为什么他们不会在没有这个的情况下出现。但我希望这能给你一个好的开始,我会继续搞砸它。
[编辑] 添加“缩放:正常;”到“#image_bar .links A”,这将完全修复它。
[编辑]刚刚对其进行了测试,以确保不需要条件 CSS,它仍然可以在经过这些修复的所有浏览器中正确显示。
[编辑]好吧,所以我再次尝试了上述修复,但由于某种原因,它们现在没有完成。所以我去尝试了我的另一个想法。开始了。
我不确定为什么在 IE 中需要背景颜色,但由于某种原因,它与 z-index 不同,将链接放在前面,然后由于它们当前有图片,我将背景颜色更改为然后我按照之前的不透明度进行操作,这样您就可以实际看到其他图像。
我希望这对你有用,我尝试了 2 次,包括重新启动可视化 CSS 编辑器,以确保它能正常工作,并且不会像上次那样愚弄我。
抱歉,答案较长,这都是思考过程的一部分。
享受!
Well there's your problem!
IEs Javascript interpreter is very finicky and when you are manipulating an object as you are now, it generally lashes out. This would be one of those time. I would guess that the problem is that you are changing the object so it considers that to have precedence.
Personally I would just simply change your code as follows (pseduocode) for the architecture.
All you have to do from here is simply either set a class/id name for each of the images so they can be easily changed out in Javascript (this would be my ideal solution)
Hope this helps,
[edit]
After taking a closer look at your site heres a few problems I found:
CSS:
It doesn't effect this, but something to fix.
Now, breaking down some of your CSS the problem with IE is that it is for some reason not allowing a link to be used on the .active class for some reason.
If you want to see what I am describing, simply take float: left; off of #image_bar .links LI
And you will see that all of the links are aligning to the center and they are going on separate lines. So this points to a positioning problem within IE.
Now to figure out how to fix this.
This is fixed now by simply adding a width to the container #image_bar UL.links
The width needs to be 962 just like your max width.
This will then make them links line up properly instead of on separate lines.
Now there is the problem of making them appear on top of the image in IE. I turned all of the links black so that I was able to see them and that made them come to the top and be click able. At this time, I'm not certain why they wouldn't be showing without that. But I hope that gives you a good start and I'll keep messing with it.
[edit] Add "zoom: normal;" to "#image_bar .links A" and that will completely fix it.
[edit] Just tested it to make sure that conditional css isn't needed, it still displays properly in all browsers with those fixes.
[edit]Okay, so I tried my above fixes one more time and for some reason they didn't go through now. So I went and tried another idea I had. Here we go.
I am not sure why it is necessary to have the background-color in IE but for some reason it, unlike z-index, is bringing the links to the front, then since they currently have pictures on them I change the background-color to that of your page so it blends in. I then follow that with your opacity from before that way you can actually see the other images.
I hope this works for you, I tried it 2 times including restarting a visual CSS editor to make sure that it works and that it wasn't just fooling me like the other time.
Sorry for the answer being longer, it was all part of the thinking process.
Enjoy!
您可以尝试为
#slideshow
设置低于 9999 的 z-index 吗?Can you try giving
#slideshow
a z-index lower than 9999 ?JavaScript 可能会覆盖您的 CSS 并为幻灯片图像提供更高的 z-index。
尝试
使用 !important 覆盖其他地方指定的任何其他 CSS 规则。
希望这有帮助
the javascript might be overriding your CSS and giving the slideshow images a higher z-index.
try
using !important overrides any other CSS rule specified elsewhere.
hope this helps