[英]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.