Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stephanie Green
3,525 PointsNav Drop Down menu
Trying to get my sub-menu to drop down and show when hovering over parent ul:
html:
<div>
<ul>
<li id="nav">
<a href="#">Menu</a>
<ul>
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Work</a>
</li>
<li>
<a href="#">Process</a>
</li>
<li>
<a href="#">Achievements</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
</li>
</ul>
</div>
css:
nav {
font-family: Helvetica, Arial, sans-serif;
float: left;
padding-left: 50px;
padding-top: 0px;
margin-top: 15px;
margin-left: -40px;
position: relative;
z-index: 2;
list-style:none;
text-decoration:none;
color: #333;
}
ul li a {
text-decoration:none;
color: #333;
}
ul li ul {
float: left;
padding-left: 50px;
padding-top: 40px;
margin-top: 15px;
margin-left: -40px;
position: relative;
list-style: none;
display:block;
z-index: 2;
visibility: hidden;
text-decoration: none;
color: #333;
background-color: #fff;
}
ul li ul: active {
visibility: visible;
}
2 Answers
Adam Moore
21,956 PointsCheck out below:
<style>
#nav{
font-family: Helvetica, Arial, sans-serif;
float: left;
padding-left: 50px;
padding-top: 0px;
margin-top: 15px;
margin-left: -40px;
position: relative;
z-index: 2;
list-style:none;
text-decoration:none;
color: #333;
}
ul li a{
text-decoration:none;
color: #333;
}
ul li ul{
float: left;
padding-left: 50px;
padding-top: 40px;
margin-top: 15px;
margin-left: -40px;
position: relative;
list-style: none;
display:block;
z-index: 2;
visibility: hidden;
text-decoration: none;
color: #333;
background-color: #fff;
}
#nav:hover ul{
visibility: visible;
}
</style>
<div>
<ul>
<li id="nav"><a href="#">Menu</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Work</a></li>
<li><a href="#">Process</a></li>
<li><a href="#">Achievements</a></li>
<li><a href="#">Contact</a></li>
</ul>
</li>
</ul>
</div>
All I did was change your nav to match the ID that you had set, which would be #nav. If it were simply a <nav> element, you wouldn't need the # prefix. Also, I changed your ul li ul: active to #nav:hover ul, which says: "When the element with the ID nav (#nav) is hovered over (:hover, with no space between #nav and :hover), do the following CSS code to its child, which is ul." Does that make sense?
Stephanie Green
3,525 PointsYOU ARE AMAZING! THANK YOU!
Adam Moore
21,956 PointsSure thing! :) Glad I could help!