如何创建垂直下拉菜单动画菜单

How to create Vertical drop down menu animated menu

我一直在尝试准确下拉该网站作为 https://www.geeksforgeeks.org/python-programming-language/

预计如下:

没有得到我真正缺少的东西,下面的代码不像上面的网站垂直下拉菜单那样灵活

我网站的子菜单没有正常显示一半被截断

这是我应用了以下代码的网站:

https://codemyquestion.blogspot.com/

代码:

 <style>
    
    body {
        background-color: #fff;
        font-size: 14px;
    }
      
     nav {
        position: relative;
        width: 180px;
    }
    
    nav ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    nav ul li {
      /* Sub Menu */
    }
    nav ul li a {
        display: block;
        background: #ebebeb;
        padding: 10px 15px;
        color: #333;
        text-decoration: none;
        -webkit-transition: 0.2s linear;
        -moz-transition: 0.2s linear;
        -ms-transition: 0.2s linear;
        -o-transition: 0.2s linear;
        transition: 0.2s linear;
    }
    nav ul li a:hover {
        background: #f8f8f8;
        color: #515151;
    }
    nav ul li a .fa {
        width: 16px;
        text-align: center;
        margin-right: 5px;
        float:right;
    }
    nav ul ul {
        background-color:#ebebeb;
    }
    nav ul li ul li a {
        background: #f8f8f8;
        border-left: 4px solid transparent;
        padding: 10px 20px;
    }
    nav ul li ul li a:hover {
        background: #ebebeb;
        border-left: 4px solid #3498db;
    }
    
    
    
    
    </style>
    
    
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
    <nav class='animated bounceInDown'>
        <ul>
            <li><a href='#profile'>Profile</a></li>
            <li><a href='#message'>Messages</a></li>
            <li class='sub-menu'><a href='#settings'>Settings<div class='fa fa-caret-down right'></div></a>
                <ul>
                    <li><a href='#settings'>Account</a></li>
                    <li><a href='#settings'>Profile</a></li>
                
                </ul>
            </li>
        
            <li class='sub-menu'><a href='#Somethin'>Something<div class='fa fa-caret-down right'></div></a>
                <ul>
                    <li><a href='#settings'>Account</a></li>
                    <li><a href='#settings'>Profile</a></li>
                
                </ul>
            </li>
        
        
            <li class='sub-menu'><a href='#message'>Help<div class='fa fa-caret-down right'></div></a>
                <ul>
                    <li><a href='#settings'>FAQ's</a></li>
                    <li><a href='#settings'>Submit a Ticket</a></li>
                    <li><a href='#settings'>Network Status</a></li>
                </ul>
            </li>
        
        </ul>
      
    </nav>
    
    
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    
    <script>
    
    
    
    $('.sub-menu ul').hide();
    $(".sub-menu a").click(function () {
        $(this).parent(".sub-menu").children("ul").slideToggle("100");
        $(this).find(".right").toggleClass("fa-caret-up fa-caret-down");
    });
    
    </script>

添加此样式

.widget ul {
    padding: 0 !important;
}

#sidebar-left-1 .widget-content nav {
    width: unset !important;
}

#sidebar-left-1 {
    margin: 0 !important;
}

我会在 'half get cut' 挑战你。根据这张图片,实际上是完全可见的:

您需要做的是在 ul 标记中添加填充,这将在右侧产生一些 space:

结果: