IE8 - 导航链接不起作用

发布于 2024-08-13 13:11:10 字数 2470 浏览 5 评论 0原文

大家好 - 我一直在尽可能多地搜索这个问题,但我所做的似乎都没有帮助。

我一直在开发一个网站(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可是我不能没有你 2024-08-20 13:11:10

您错过了:

.nav a, .nav2 a  {
    left: 0;
}

这应该可以解决问题。始终设置垂直(顶部底部水平( ) 使用 position:absolute 时的位置。

更新

每当设置背景时,它就会开始按预期工作。通过大量测试,您可能会找到解决问题的不同方法。但这就是我要做的:

最佳方式

  1. 要么删除 img 标签,要么隐藏它们,然后将它们应用为 background-image 到您的 a 标签。
  2. a 标记上的 position 更改为 relative 而不是 absolute,因为它们将是父 div

QUICK WAY

.nav a, .nav 2 { background: url(/images/shim.png) }

其中 shim.png 是 8 位完全透明的单像素 PNG。 8 位 PNG shim 比相同尺寸(1 像素)的 gif 小,并且一切仍将按计划进行。

You are missing:

.nav a, .nav2 a  {
    left: 0;
}

That should fix the problem. Always set a vertical (top or bottom) and horizontal (left or right) placement when using position: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:

  1. Either get rid of the img tags or hide them, and instead apply them as background-image to your a tags.
  2. Change the position on the a tags to relative instead of absolute as they would be the only visible child of the parent div

QUICK WAY

.nav a, .nav 2 { background: url(/images/shim.png) }

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.

末蓝 2024-08-20 13:11:10

为 IE8 提供与 IE7 相同的样式,然后将以下元素放入文档头中:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

这将使 IE8 模拟 IE7。因为您对 IE7 没有任何问题,所以我认为这对您有用。

Serve the same styles to IE8 that you serve to IE7, and then put the following element in the document head:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

This will make IE8 emulate IE7. Because you are having no issues with IE7, I presume this would work for you.

眼眸印温柔 2024-08-20 13:11:10

不完全确定那里发生了什么,但链接和图像元素的分层似乎存在某种问题(可能是 IE8 错误)。当我将 .nav img、.nav2 imgz-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文