垂直子菜单布局和行为不正确

时间:2013-01-15 15:23:55

标签: css3 submenu onhover

垂直子菜单位置正确但链接位于彼此之上。当悬停在主菜单中时它不会隐藏。悬停在菜单外面时隐藏。我不知道在css中添加/更改的内容。

Vertical submenu

nav {
    padding-top: 183px;
    margin-left: auto;
    margin-right: auto;
}
    ul {
    padding: 0;
    margin: 0;
}
nav ul {
    list-style: none;
    font-weight: bold;
    font-size: 20px;
    margin: 5px;
    width: 200px;
}
nav ul ul {
    display: none;
    margin: 0px;
    padding: 0px;
}
nav ul li {
    float: left;
}
nav ul a {
    display: block;
    width: 145px;
    text-align: center;
    text-decoration: none;
    color: #fff;
    border: 1px solid #004c99;
    border-radius: 8px;
    margin-right: auto;
    margin-left: auto;
    padding-top: 5px;
    padding-right: 9px;
    padding-bottom: 5px;
    padding-left: 9px;
}
nav ul a:active       {
    background: rgba(255,255,255,0.4);
    color: #FFF;
}
nav ul li a:hover, ul a:focus {
    text-decoration: none;
    background-color: #6699cc;
    color: #FFFFFF;
}
nav ul a:link, nav ul a:visited {
    background: rgba(255,255,255,0.2);
    color: #FFFFFF;
}
nav ul li a {
    display: block;
    margin-top: 0px;
}
nav ul ul li {
    float: none;
    position: relative;
}
nav ul ul li a {
    color: #fff;
    margin-top: -35px;
    position: relative;
    margin-left: 165px;
}
nav ul ul li a:hover {
    background: #6699cc;
}
nav ul ul li a:active, ul ul li a:link , ul ul li a:visited{
    background-color: #3370AD;
}
nav ul li:hover {
    margin-top: 0px;
}
nav ul li:hover > ul{
    display: block;
    position: absolute;
}
nav ul:after {
    content: "";
    clear: both;
    display: block;
}       

提前致谢!

2 个答案:

答案 0 :(得分:0)

更改你的导航信息{     显示:块;     margin-top:0px;}到... margin-top:5px并查看是否能完成这项工作。这将解决间距问题

答案 1 :(得分:0)

当我错误地嵌套子菜单时,发生了这种情况:

<ul id="main menu">

    <li> 
        <a>Menu item</a> 
        <!-- DO NOT CLOSE THIS LI TAG YET! -->

        <ul>
            <li>Submenu item</li>
        </ul>

    </li> <!-- NOW YOU CAN CLOSE IT -->

</ul>