1

我正在使用 css3 菜单的示例,我的问题是子菜单的子菜单,在将其移动到父级的底部后,鼠标无法轻易移动。

CSS3:

body {
    font: 0.8em/1.5em Arial, Helvetica, sans-serif;
    background: none repeat scroll 0% 0% rgb(235, 235, 235);
    width: 900px;
    margin: 100px auto;
    color: rgb(102, 102, 102);
}
a {
    color: rgb(51, 51, 51);
}
#nav {
    margin: 0px;
    padding: 7px 6px 0px;
    background: url('gradient.png') repeat-x scroll 0px -110px rgb(125, 125, 125);
    line-height: 100%;
    border-radius: 2em 2em 2em 2em;
}
#nav li {
    margin: 0px 5px;
    padding: 0px 0px 8px;
    float: left;
    position: relative;
    list-style: none outside none;
}
#nav a {
    font-weight: bold;
    color: rgb(231, 229, 229);
    text-decoration: none;
    display: block;
    padding: 8px 20px;
    margin: 0px;
    text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3);
}
#nav a:hover {
    background: none repeat scroll 0% 0% rgb(0, 0, 0);
    color: rgb(255, 255, 255);
}
#nav .current a, #nav li:hover > a {
    background: url('gradient.png') repeat-x scroll 0px -40px rgb(102, 102, 102);
    color: rgb(68, 68, 68);
    border-top: 1px solid rgb(248, 248, 248);
    box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2);
    text-shadow: 0px 1px 0px rgb(255, 255, 255);
}
#nav ul li:hover a, #nav li:hover li a {
    background: none repeat scroll 0% 0% transparent;
    border: medium none;
    color: rgb(102, 102, 102);
}
#nav ul a:hover {
    background: url('gradient.png') repeat-x scroll 0px -100px rgb(0, 120, 255) ! important;
    color: rgb(255, 255, 255) ! important;
    text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.1);
}
#nav li:hover > ul {
    display: block;
}
#nav ul {
    display: none;
    margin: 0px;
    padding: 0px;
    width: 185px;
    position: absolute;
    top: 35px;
    left: 0px;
    background: url('gradient.png') repeat-x scroll 0px 0px rgb(221, 221, 221);
    border: 1px solid rgb(180, 180, 180);
    border-radius: 10px 10px 10px 10px;
    box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3);
}
#nav ul li {
    float: none;
    margin: 0px;
    padding: 0px;
}
#nav ul a {
    font-weight: normal;
    text-shadow: 0px 1px 0px rgb(255, 255, 255);
}
#nav ul ul {
    left: 181px;
    top: 23px;
}
#nav ul li:first-child > a {
}
#nav ul li:last-child > a {
}
#nav:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0px;
}
#nav {
    display: inline-block;
}
html[xmlns] #nav {
    display: block;
}

HTML:

<ul id="nav">
    <li><a href="http://www.ndesign-studio.com/">My Projects</a>
        <ul>
            <li><a href="http://www.ndesign-studio.com/">N.Design Studio</a>
                <ul>
                    <li><a href="http://www.ndesign-studio.com/portfolio">Portfolio</a></li>
                    <li><a href="http://www.ndesign-studio.com/wp-themes">WordPress Themes</a></li>
                    <li><a href="http://www.ndesign-studio.com/wallpapers">Wallpapers</a></li>
                    <li><a href="http://www.ndesign-studio.com/tutorials">Illustrator Tutorials</a></li>
                </ul>
            </li>
            <li><a href="http://www.webdesignerwall.com/">Web Designer Wall</a>
                <ul>
                    <li><a href="http://jobs.webdesignerwall.com/">Design Job Wall</a></li>
                </ul>
            </li>
            <li><a href="http://icondock.com/">IconDock</a></li>
            <li><a href="http://bestwebgallery.com/">Best Web Gallery</a></li>
        </ul>
    </li>
</ul>

下面的代码是在 jsfiddle.demo 上提交的,如何父级可以责备这样的 az 子菜单的子菜单 JSFIDDLE

4

1 回答 1

0

问题是子菜单在悬停时显示。由于您已将大子菜单设置为从顶部显示 23px,如果您将鼠标向右移动,它不再悬停在子菜单上,因此菜单消失。

要修复它,您需要使大子菜单与子菜单垂直对齐,以便在大子菜单获得悬停之前它不会失去悬停。您可以通过将顶部值设置为 0 来做到这一点:

#nav ul ul {
    left: 181px;
    top: 0;
}

http://jsfiddle.net/CZLuq/1/

于 2013-05-28T21:30:49.567 回答