CSS 水平悬停导航在 IE 7 中消失

发布于 2024-10-17 16:21:32 字数 3729 浏览 0 评论 0原文

本质上,我一直在关注 A List Apart 中 Nick 的代码:

http://www.alistapart.com /articles/horizdropdowns/

我做了一些修改,主要是 - 我使用背景图像而不是背景颜色。一切都按预期工作,除了在 IE7 中,当尝试将鼠标悬停在其中一个子项上时,悬停列表(右侧)会消失。

更改如下:

#sidebar ul.subnav {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 276px;
}

#sidebar ul.subnav li {
    position: relative;
}

#sidebar ul.subnav li ul {
    position: absolute;
    left: 275px;
    top: 0;
    display: none;
    width: 276px;
    height: 58px;
    z-index: 300;
}

#sidebar ul.subnav li a {
    display: block;
    text-decoration: none;
    color: #444444;
    height: 58px;
    line-height: 58px;
    text-indent: 35px;
    font-size: 14px;
    z-index: 300;
}

#sidebar ul.subnav li:hover ul { display: block; }
#sidebar ul.subnav li.over ul { display: block; }
#sidebar li.sub-item-1 { background: url('images/subnav-1.jpg') 0 no-repeat; }
#sidebar li.sub-item-2 { background: url('images/subnav-2.jpg') 0 no-repeat; }
#sidebar li.sub-item-3 { background: url('images/subnav-3.jpg') 0 no-repeat; }
#sidebar li.sub-item-4 { background: url('images/subnav-4.jpg') 0 no-repeat; }

#sidebar ul.subnav li.sub-item-1 ul li { background: url('images/rev-subnav-1.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-2 ul li { background: url('images/rev-subnav-2.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-3 ul li { background: url('images/rev-subnav-3.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-4 ul li { background: url('images/rev-subnav-4.jpg') 0 no-repeat; }

/* Fix IE. Hide from IE Mac \*/
* html ul li { float: left; }
* html ul li a { height: 1%; }
/* End */

这是 HTML,它没有改变太多:

         <ul class="subnav"> 
            <li class="sub-item-1"><a href="#">Nav Item 1</a>
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
            <li class="sub-item-2"><a href="#">Nav Item 2</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
            <li class="sub-item-3"><a href="#">Nav Item 3</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li>
            <li class="sub-item-4"><a href="#">Nav Item 4</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
        </ul>

我尝试遵循此处其他主题中的一些建议,但似乎没有任何帮助。此时我可能错过了一些小事。有人有什么想法吗?

编辑:悬停导航覆盖的内容区域导致了问题。

CSS 如下:

#content {
    width: 641px;
    min-height: 300px;
    position: absolute;
    top: 0;
    left: 278px;
}

如果我删除它,导航就可以正常工作。否则我必须找到一种方法来设计该内容区域的样式。

编辑#2:

向此内容元素(位于下拉菜单后面)添加背景颜色可修复 IE7 中的问题。

In essence, I've been following Nick's code from A List Apart:

http://www.alistapart.com/articles/horizdropdowns/

I've made a few alterations, mainly - I'm using background images instead of a background color. Everything works as expected, except that in IE7, the hovering list (on the right) disappears when trying to hover over one of the child items.

Alterations are as follows:

#sidebar ul.subnav {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 276px;
}

#sidebar ul.subnav li {
    position: relative;
}

#sidebar ul.subnav li ul {
    position: absolute;
    left: 275px;
    top: 0;
    display: none;
    width: 276px;
    height: 58px;
    z-index: 300;
}

#sidebar ul.subnav li a {
    display: block;
    text-decoration: none;
    color: #444444;
    height: 58px;
    line-height: 58px;
    text-indent: 35px;
    font-size: 14px;
    z-index: 300;
}

#sidebar ul.subnav li:hover ul { display: block; }
#sidebar ul.subnav li.over ul { display: block; }
#sidebar li.sub-item-1 { background: url('images/subnav-1.jpg') 0 no-repeat; }
#sidebar li.sub-item-2 { background: url('images/subnav-2.jpg') 0 no-repeat; }
#sidebar li.sub-item-3 { background: url('images/subnav-3.jpg') 0 no-repeat; }
#sidebar li.sub-item-4 { background: url('images/subnav-4.jpg') 0 no-repeat; }

#sidebar ul.subnav li.sub-item-1 ul li { background: url('images/rev-subnav-1.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-2 ul li { background: url('images/rev-subnav-2.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-3 ul li { background: url('images/rev-subnav-3.jpg') 0 no-repeat; }
#sidebar ul.subnav li.sub-item-4 ul li { background: url('images/rev-subnav-4.jpg') 0 no-repeat; }

/* Fix IE. Hide from IE Mac \*/
* html ul li { float: left; }
* html ul li a { height: 1%; }
/* End */

Here's the HTML, it hasn't changed too much:

         <ul class="subnav"> 
            <li class="sub-item-1"><a href="#">Nav Item 1</a>
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
            <li class="sub-item-2"><a href="#">Nav Item 2</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
            <li class="sub-item-3"><a href="#">Nav Item 3</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li>
            <li class="sub-item-4"><a href="#">Nav Item 4</a> 
                <ul> 
                    <li><a href="#">Link 1</a></li> 
                    <li><a href="#">Link 2</a></li> 
                    <li><a href="#">Link 3</a></li> 
                </ul> 
            </li> 
        </ul>

I tried following some of the advice in the other topics here, but none seemed to help. I'm probably missing something minor at this point. Anyone have any ideas?

Edit: The content area that the hovered navigation was covering is causing the issue.

CSS is as follows:

#content {
    width: 641px;
    min-height: 300px;
    position: absolute;
    top: 0;
    left: 278px;
}

If I remove this, the navigation works fine. I'll have to find a way to style that content area otherwise.

Edit #2:

Adding a background color to this content element (which sits behind the dropdown) fixes the issue in IE7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

顾铮苏瑾 2024-10-24 16:21:32

只需添加背景颜色即可在 IE7 中使用:

#sidebar ul.subnav li a {
    background: #fff
}

现场演示编辑

如果这在您的实际页面上不起作用,我有一个问题想问你。

您在页面上使用什么文档类型? (显示文件的第一行)

Simply adding a background colour makes it work in IE7:

#sidebar ul.subnav li a {
    background: #fff
}

Live Demo (edit)

If this doesn't work on your actual page, I have one question for you.

What doctype are you using on your page? (show the first lines of your file)

最美不过初阳 2024-10-24 16:21:32

以下内容对我有用。

background: url("http://www.kvammetravel.com/images/menu_background.gif") repeat-x scroll left top transparent;

检查下面的屏幕截图
在此处输入图像描述

适用于 IE7。如果这仍然不适合您,您需要将您的工作代码发布到 jsfiddle.net 中,以便我可以查看。

The Following works for me.

background: url("http://www.kvammetravel.com/images/menu_background.gif") repeat-x scroll left top transparent;

Check screenshot below
enter image description here

Works in IE7. If that still doesn't work for you, you need to post your working code in jsfiddle.net so i can take a look.

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