2

我正在尝试在我拥有的这个已经创建的水平菜单中获得一个子菜单,但这样做没有运气。当有人将鼠标悬停在子菜单部分的右侧时,我希望子菜单悬停在子菜单部分的右侧,然后在子菜单项上没有悬停时隐藏。

是否可以为这些子子菜单项获得另一个子子子菜单?

我很难做到这一点。这是我到目前为止的代码:

http://jsfiddle.net/ndn4life104/pp5Mf/

HTML

<ul> <li><a href="#">Menu 1</a> <div class="primary-nav-sub-menu-2"> <ul class="column">
     <li><a href="#">Submenu</a></li>
         <li><a href="#">part1</a></li>                                                                                                                                                                                                                                         
         <li><a href="#">part2</a></li>                                                                                         
         <li><a href="#">part3</a></li>                                                                                             
         <li><a href="#">part4</a></li>
</ul>   
     <ul class="column">                                                                                            
     <li><a href="#">part5</a></li>                                                                                                                                                                                                         
     <li><a href="#">part6</a></li>                                                                                         
     <li><a href="#">part7</a></li>                                                                                                         
     <li><a href="#">part8</a></li> 

    </ul></div> </li></ul>                                                                                                  
4

1 回答 1

0

小提琴

尝试这个:

HTML:

<head><link rel="stylesheet" type="text/css" href="m.css"></head>
<div id="top_menu">                     
            <ul>
                <li class="first">menu1                 
                    <div id="submenu">
                        <ul class="abc">
                            <li class="second">item1    
                                <div id="submenu2">
                                    <ul class="abc">
                                        <li class="second">item1_1
                                            <div id="submenu3">
                                                <ul class="abc">
                                                    <li class="second">item1_1_1</li>
                                                    <li class="second">item1_1_2</li>
                                                    <li class="second">item1_1_3</li>
                                                </ul>
                                            </div>  
                                        </li>
                                        <li class="second">item1_2</li>
                                        <li class="second">item1_3</li>
                                    </ul>
                                </div>                              
                            </li>
                            <li class="second">item2
                                <div id="submenu2">
                                    <ul class="abc">
                                        <li class="second">item2_1</li>
                                        <li class="second">item2_2</li>
                                        <li class="second">item2_3</li>
                                    </ul>
                                </div>                              
                            </li>
                            <li class="second">item3
                                <div id="submenu2">
                                    <ul class="abc">
                                        <li class="second">item3_1</li>
                                        <li class="second">item3_2</li>
                                        <li class="second">item3_3</li>
                                    </ul>
                                </div>                              
                            </li>
                        </ul>
                    </div>
                </li>   

                <li class="first">menu2
                    <div id="submenu">
                        <ul class="abc">
                            <li class="second">item1</li>
                            <li class="second">item2</li>
                            <li class="second">item3</li>
                            <li class="second">item4</li>
                        </ul>
                    </div>
                </li>

            </ul>   
        </div>

CSS:

ul{
    padding:10px;
    padding-right:0px;
}
li.first{
    display:block;
    display:inline-block;
    padding:5px;
    padding-right:25px;
    padding-left:25px;
    cursor:pointer;
}
li.second{
    list-style:none;
    margin:0px;
    padding:5px;
    padding-right:25px;
    margin-bottom:5px;
    cursor:pointer;
}
#submenu li.second:hover{
    background:red;
    border-radius:5px;
}

#submenu2 li.second:hover{
    background:green;
    border-radius:5px;
}
/*********MAIN LOGIC***************/

#submenu,#submenu2,#submenu3{
    visibility:hidden;
}
#top_menu li.first:hover #submenu,#submenu li.second:hover #submenu2,#submenu2 li.second:hover #submenu3{
    visibility:visible;
}
/**********STYLING SUBMENUS**************/
#submenu{
    padding-right:0px;
    text-align:left;
    position:absolute;
    background:white;
    box-shadow:0px 0px 5px;
    border-radius:5px;
}
#submenu2{
    text-align:left;
    position:absolute;
    left:70px;
    top:0px;
    background:red;
    box-shadow:0px 0px 5px;
    border-radius:5px;
}
#submenu3{
    text-align:left;
    position:absolute;
    left:80px;
    top:0px;
    background:green;
    box-shadow:0px 0px 5px;
    border-radius:5px;
}

只需了解此代码背后的逻辑,您就可以制作任意数量的子菜单。

于 2013-10-02T12:25:59.330 回答