Conner Dassen
Conner Dassen

Reputation: 740

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. 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. Does anyone know how to do this? I already tried something with z-index, but that doesn't work. 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.

Upvotes: 0

Views: 93

Answers (1)

Nutshell
Nutshell

Reputation: 8537

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

.nav ul > li {position: relative;}

Be careful about relative and absolute positions.

You can animate it with CSS on :hover event or with javascript. 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; visibility:hidden; or opacity:0; or height:0;

Here is a CSS solution I've made : See this fiddle

Upvotes: 1

Related Questions