css3子菜单的子菜单移到父母的底部

时间:2013-05-28 21:17:42

标签: html css css3

我正在使用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上提交的,如何对父进行chide这样的子菜单的子菜单 JSFIDDLE

1 个答案:

答案 0 :(得分:0)

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

要修复它,您需要使宏子菜单与子菜单垂直对齐,以便在子项获得悬停之前不会丢失悬停。您可以通过将顶部值设置为0来执行此操作:

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

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