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
Arturo Espinoza
9,181 PointsHow do I position drop down menus under main menu
how to position drop down menus under main menu
3 Answers
LaVaughn Haynes
12,397 PointsIn your CSS, add position: relative; in your ul rule
ul {
position: relative;
list-style-type: none;
float: right;
font-size: 13px;
margin: 25px 115px 25px 0;
padding: 0;
text-align: center;
text-transform: uppercase;
}
You have the sub-menu positioned absolute so you need to make it's parent element positioned relative so that it stays contained inside of it.
Arturo Espinoza
9,181 PointsHere is my updated link. The sub menu doesn't appear directly under the menu I hover over. For example if you hover over "Contact" the dropdown appears in the same location as "Menu" and "Menu2''
Arturo Espinoza
9,181 PointsPERFECT! It worked. A million thanks.
Arturo Espinoza
9,181 PointsArturo Espinoza
9,181 PointsI tried that but still doesn't work.
LaVaughn Haynes
12,397 PointsLaVaughn Haynes
12,397 PointsThis doesn't work for you? https://jsfiddle.net/406somug/1/
LaVaughn Haynes
12,397 PointsLaVaughn Haynes
12,397 PointsI get what you mean now. I'm sorry. Add the position relative to the li rule NOT the ul. Also, in your nested ul, change the left property from auto to 0
Like this: https://jsfiddle.net/j4b9ntmk/12/