Add Sub-Sub-Menus to a CSS menu with Sub-Menus

前端 未结 2 770
小蘑菇
小蘑菇 2020-12-18 10:45

I have a CSS manu that I am using with sub menus. I was wondering how I would go about adding a sub-submenu to it. For example, I hover over the main menu item and the sub

2条回答
  •  独厮守ぢ
    2020-12-18 11:33

    Here is how I would approach what you are looking for: http://jsfiddle.net/Dg3yQ/26/

    I took some liberties on revising the CSS. The revised CSS reduced the code by a couple hundred characters and I believe it accomplishes what you intended. I hope this helps.

    EDITED: Added a streamlined code example with comments to this answer on how these sub menus can be accomplished.

    #nav {
        list-style:none inside;
        margin:0;
        padding:0;
        text-align:center;
        }
    
    #nav li {
        display:block;
        position:relative;
        float:left;
        background: #006633; /* menu background color */
        }
    
    #nav li a {
        display:block;
        padding:0;
        text-decoration:none;
        width:200px; /* this is the width of the menu items */
        line-height:35px; /* this is the hieght of the menu items */
        color:#ffffff; /* list item font color */
        }
            
    #nav li li a {font-size:80%;} /* smaller font size for sub menu items */
        
    #nav li:hover {background:#003f20;} /* highlights current hovered list item and the parent list items when hovering over sub menues */
    
    
    
    /*--- Sublist Styles ---*/
    #nav ul {
        position:absolute;
        padding:0;
        left:0;
        display:none; /* hides sublists */
        }
    
    #nav li:hover ul ul {display:none;} /* hides sub-sublists */
    
    #nav li:hover ul {display:block;} /* shows sublist on hover */
    
    #nav li li:hover ul {
        display:block; /* shows sub-sublist on hover */
        margin-left:200px; /* this should be the same width as the parent list item */
        margin-top:-35px; /* aligns top of sub menu with top of list item */
        }

提交回复
热议问题