简体   繁体   English

如何隐藏下拉菜单?

[英]How do I hide my dropdown menu?

I am making a website using html, and now I want to make a dropdown menu wich animates down slowly. 我正在使用html制作网站,现在我想制作一个动画缓慢的下拉菜单。 This is my code: 这是我的代码:

<html>
<head>
    <style type="text/css">
    .nav {
    background-color: #25AAA0;
    position: fixed;
    width: 100%;
    margin: 0;
    padding: 0;
    z-index: 1000;
}

    .nav_wrapper {
    width: 90%;
    margin: 0 auto;
    text-align: left;
}
    .nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: relative;
}

    .nav ul li {
    display: inline-block;
}

    .nav ul li:hover {
    background-color: #66C3BC;
}

    .nav ul li a,visited {
    text-decoration: none;
    color: white;
    padding: 15px;
    display: block;
}

    .nav ul li a:hover {
    padding: 15px;

}
    .nav ul #dropdown {
    position: absolute;
    background-color: black;
    top: 0
}

    </style>
</head>

<body>
<div class="nav">
    <div class="nav_wrapper">
        <ul>
            <li><a href="#">Vanilla</a><ul id="dropdown">
                <li><a href="#">Survival</a></li>
                <li><a href="#">Creative</a></li>
                </ul></li><li>
            <a href="#">Modded</a></li><li>
            <a href="#">Servers</a></li><li>
            <a href="#">Help</a></li>
        </ul>
    </div>
</div>
</body>
</html>

This is what it looks like. 就是它的样子。 What needs to happen is that the black part is behind and not in front of the rest of the navigation menu, so I can slide it down using jQuery. 需要发生的是黑色部分在导航菜单其余部分的后面而不是前面,因此我可以使用jQuery将其向下滑动。 Does anyone know how to do this? 有谁知道如何做到这一点? I already tried something with z-index, but that doesn't work. 我已经尝试过使用z-index进行操作,但这不起作用。 And please don't tell me how I can animate the sliding down, I'm not asking that, I'm asking how I can put the black stuff behind the rest of the navigation bar. 而且,请不要告诉我如何为向下滑动设置动画,我不是在问这个问题,而是在问我如何将黑色的东西放在导航栏的其余部分后面。

I hope you react soon. 希望您能尽快做出反应。

.nav ul #dropdown {
    position: absolute;
    background-color: black;
    top: 50px;
}

.nav ul > li {position: relative;}

Be careful about relative and absolute positions. 注意relative位置和absolute位置。

You can animate it with CSS on :hover event or with javascript. 您可以在:hover事件或javascript上使用CSS为它设置动画。 I can help you with this if you wants but it's better for you to try first :) 如果您愿意,我可以为您提供帮助,但是最好先尝试一下:)

You can hide it with several ways in CSS like display:none; 您可以在CSS中使用多种方式将其隐藏,例如display:none; visibility:hidden; or opacity:0; opacity:0; or height:0; height:0;

Here is a CSS solution I've made : See this fiddle 这是我制作的CSS解决方案: 请参阅此小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复Javascript中的下拉菜单? - How do I fix my dropdown menu in Javascript? 如何在菜单下拉菜单中创建平滑过渡? - How do I create a smooth transition in my menu dropdown? 如何使用Javascript创建依赖下拉选择菜单选项显示/隐藏另一个下拉选择菜单? - How do I make a dependent dropdown select menu choice show/hide another dropdown select menu using Javascript? 在 Swashbuckle / Swagger; 如何根据其他选择的值隐藏下拉菜单 - In Swashbuckle / Swagger; How do I hide a dropdown menu based on anothers selected value 单击屏幕上的任意位置时如何隐藏下拉菜单? (javascript) - How do I hide the dropdown menu when click anywhere on the screen? (javascript) 如何使现有菜单变成响应式下拉菜单? - How do I make turn my existing menu into a responsive dropdown menu? 如何使用自己的自定义下拉菜单控制由DataTables生成的选择菜单? - How do I control a DataTables-generated select menu with my own custom dropdown menu? 如何根据数组中的内容将“禁用”属性切换到下拉菜单? - How do I toggle the `disable` attribute to my dropdown-menu base on what I have in my array? 我如何在dynamicjs中创建一个下拉菜单 - How do I create a dropdown menu in kineticjs 如何在html中创建下拉菜单? - How do I make a dropdown menu in html?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM