pure css vertical menu with submenu

前端 未结 1 764
别跟我提以往
别跟我提以往 2021-01-18 08:21

I did my research and was able to replicate what I\'m looking for, well kind of--I just need help with a more specific vertical, pure CSS, menu.

I want my sub-menu p

相关标签:
1条回答
  • 2021-01-18 08:27

    Try this one and I think it will help

    HTML

        <div id="nav">
        <ul class="top-level">
            <li><a href="#">This is a long text</a>
                <ul class="sub-level">
                    <li><a href="#">Sub Menu Item 1</a></li>
                    <li><a href="#">Sub Menu Item 2</a></li>
                    <li><a href="#">Sub Menu Item 3</a></li>
                    <li><a href="#">Sub Menu Item 3</a></li>
                </ul>
            </li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact me here</a></li>
            <li><a href="#">Help</a>
               <ul class="sub-level">
                    <li><a href="#">Sub Menu Item 1</a></li>
                    <li><a href="#">Sub Menu Item 2</a></li>
                    <li><a href="#">Sub Menu Item 3</a></li>
                </ul>
            </li>
        </ul>
    </div>
    

    CSS

    #nav {font-size:0.75em; width:150px;}
    #nav ul {margin:0px; padding:0px;}
    #nav li {list-style: none;} 
    
    ul.top-level {background:#FFFFFF;}
    ul.top-level li {
     border: #FF0000 solid; 
     border-width: 1px;
    }
     #nav ul.sub-level {border:1px solid yellow;}
    #nav a {
     color: #000000;
     cursor: pointer;
     display:block;
     height:25px;
     line-height: 25px;
     text-indent: 10px;
     text-decoration:none;
     width:100%;
    }
    #nav a:hover{
     text-decoration:underline;
    }
    
    #nav li:hover {
     background: #f90;
     position: relative;
    }
    ul.sub-level {
        display: none;  
    }
    li:hover .sub-level {
        background: #999;
        border: #fff solid;
        border-width: 1px;
        display: block;
        position: absolute;
        left: 75px;
        top: 5px;
    }
    ul.sub-level li {
        border: none;
        float:left;
        width:150px;
    }
    
    #nav .sub-level {
        background: #FFFFFF;
    }
    
    0 讨论(0)
提交回复
热议问题