IE8 - 导航链接不起作用
大家好 - 我一直在尽可能多地搜索这个问题,但我所做的似乎都没有帮助。
我一直在开发一个网站(www.philipdukes.co.uk),虽然导航似乎在 FF、Safari、chrome、甚至 IE6(奇迹般地)中工作正常,但在我的系统上,它在 IE8 中惨败:导航链接不起作用。
我将鼠标悬停在它们上,获得翻转动画,但它们不可“点击”。它们是基本的文本链接,文本在屏幕外对齐,然后它们代表的区域应该是可单击的。填充空间的图像不是链接。如果删除图像,我可以单击该区域,如果删除文本对齐,我可以单击链接文本(但仅限链接文本)。
这让我发疯,因为这是我在一切完全正常工作之前需要排序的最后一件事......
导航栏的代码在这里:
<div class="navHolder">
<div class="nav current-home">
<div id="home"><img src="images/nav/home.png" alt="home." /><a href="index.html">home.</a></div>
<div id="bio"><img src="images/nav/bio.png" alt="biography." /><a href="bio.html">biography.</a></div>
<div id="media"><img src="images/nav/media.png" alt="media." /><a href="media.html">media.</a></div>
</div>
<div class="nav2 current-home">
<div id="press"><img src="images/nav/press.png" alt="press." /><a href="press.html">press.</a></div>
<div id="pdr"><img src="images/nav/pdr.png" alt="plane dukes rahman trio." /><a href="pdr.html">Plane Dukes Rahman Trio.</a></div>
<div id="contact"><img src="images/nav/contact.png" alt="contact." /><a href="contact.php">contact.</a></div>
</div>
CSS样式在这里(也欢迎这里的任何优化!):
/*
*
* BEGIN NAV SECTION
*
*/
.navHolder{
position: relative;
width: 100%;
height: 100px;
margin: 0;
padding: 0;
}
.nav, .nav2 {
width: 600px;
height: 50px;
position: relative;
overflow: hidden;
margin: 0 auto;
padding: 0;
top: 0;
}
#home, #bio, #media, #press, #pdr, #contact{
position: absolute;
top: 0px;
overflow: hidden;
width: 200px;
height: 50px;
background: url(images/nav/nav-back.png) 0 0 no-repeat;
}
.nav a, .nav2 a{
position: absolute;
z-index: 100;
display: block;
top: 0px;
height: 50px;
width: 200px;
text-indent: -9000px;
}
.nav img, .nav2 img{
position: relative;
z-index: 50;
width: 200px;
height: 50px;
}
#home, #press{
left: 0;
}
#bio, #pdr{
left: 200px;
}
#media, #contact{
left: 400px;
}
.current-home #home, .current-bio #bio, .current-contact #contact, .current-press #press, .current-pdr #pdr, .current-media #media{
background-position: 0 -246px;
}
Hey all - I've been googling this as much as possible, but nothing I do seems to help.
I've been working on a website (www.philipdukes.co.uk), and although the nav seems to work fine in FF, Safari, chrome, even IE6 (miraculously), on my system here it fails miserably in IE8: the navigation links don't work.
I hover on them, get the rollover animation, but they're not "clickable". They're basic text links, text-aligned off the screen, and then the area that they represent should be clickable. The image that fills the space isn't the link. If I remove the image I can click the area, and if I remove the text-align I can click the link text (but only the link text).
It's driving me nuts, as its the last thing I need to sort before everythings fully working...
The code for the nav bar is here:
<div class="navHolder">
<div class="nav current-home">
<div id="home"><img src="images/nav/home.png" alt="home." /><a href="index.html">home.</a></div>
<div id="bio"><img src="images/nav/bio.png" alt="biography." /><a href="bio.html">biography.</a></div>
<div id="media"><img src="images/nav/media.png" alt="media." /><a href="media.html">media.</a></div>
</div>
<div class="nav2 current-home">
<div id="press"><img src="images/nav/press.png" alt="press." /><a href="press.html">press.</a></div>
<div id="pdr"><img src="images/nav/pdr.png" alt="plane dukes rahman trio." /><a href="pdr.html">Plane Dukes Rahman Trio.</a></div>
<div id="contact"><img src="images/nav/contact.png" alt="contact." /><a href="contact.php">contact.</a></div>
</div>
and the css styling is here (any optimization here is also welcome!):
/*
*
* BEGIN NAV SECTION
*
*/
.navHolder{
position: relative;
width: 100%;
height: 100px;
margin: 0;
padding: 0;
}
.nav, .nav2 {
width: 600px;
height: 50px;
position: relative;
overflow: hidden;
margin: 0 auto;
padding: 0;
top: 0;
}
#home, #bio, #media, #press, #pdr, #contact{
position: absolute;
top: 0px;
overflow: hidden;
width: 200px;
height: 50px;
background: url(images/nav/nav-back.png) 0 0 no-repeat;
}
.nav a, .nav2 a{
position: absolute;
z-index: 100;
display: block;
top: 0px;
height: 50px;
width: 200px;
text-indent: -9000px;
}
.nav img, .nav2 img{
position: relative;
z-index: 50;
width: 200px;
height: 50px;
}
#home, #press{
left: 0;
}
#bio, #pdr{
left: 200px;
}
#media, #contact{
left: 400px;
}
.current-home #home, .current-bio #bio, .current-contact #contact, .current-press #press, .current-pdr #pdr, .current-media #media{
background-position: 0 -246px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您错过了:
这应该可以解决问题。始终设置垂直(
顶部
或底部
)和水平(左
或右
) 使用position:absolute
时的位置。更新
每当设置
背景
时,它就会开始按预期工作。通过大量测试,您可能会找到解决问题的不同方法。但这就是我要做的:最佳方式:
img
标签,要么隐藏它们,然后将它们应用为background-image
到您的a
标签。a
标记上的position
更改为relative
而不是absolute
,因为它们将是父div
QUICK WAY
其中
shim.png
是 8 位完全透明的单像素 PNG。 8 位 PNG shim 比相同尺寸(1 像素)的 gif 小,并且一切仍将按计划进行。You are missing:
That should fix the problem. Always set a vertical (
top
orbottom
) and horizontal (left
orright
) placement when usingposition:absolute
.UPDATE
Anytime a
background
is set, it starts working as expected. Through a lot of testing, you will probably find a different way of fixing the problem. But this is what I would do:BEST WAY:
img
tags or hide them, and instead apply them asbackground-image
to youra
tags.position
on thea
tags torelative
instead ofabsolute
as they would be the only visible child of the parentdiv
QUICK WAY
Where
shim.png
is a 8-bit fully transparent, one pixel PNG. A 8-bit PNG shim is smaller than the same dimension (1 pixel) gif, and everything will still work as planned.为 IE8 提供与 IE7 相同的样式,然后将以下元素放入文档头中:
这将使 IE8 模拟 IE7。因为您对 IE7 没有任何问题,所以我认为这对您有用。
Serve the same styles to IE8 that you serve to IE7, and then put the following element in the document head:
This will make IE8 emulate IE7. Because you are having no issues with IE7, I presume this would work for you.
不完全确定那里发生了什么,但链接和图像元素的分层似乎存在某种问题(可能是 IE8 错误)。当我将
.nav img、.nav2 img
的z-index
更改为任何负值而不是 50 时,链接将变为可点击。不过,我不确定在这种情况下这是否可行,因为负 z 索引可能会导致图像不再可见。
Not entirely sure what's going on there, but seems to be some kind of problem (maybe an IE8 bug) with the layering of the link and image elements. When I change the
z-index
of.nav img, .nav2 img
to any negative value instead of 50, then the links become clickable.I'm not sure if that is a practical possibility in this case, though, since the negative z-index might cause the images to no longer be visible.