4

I am having some kind of problem with my css and I am really frustrated over this ? HTML:

<div id="nav">
    <ul>
        <li><a href="#">Home</a>
            <ul>
                <li><a href="#">More</a></li>
                <li><a href="#">Hawa</a></li>
            </ul>
        </li>
        <li><a href="#">Resume</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>

CSS:

#nav {background: #008080;position:relative;}
#nav ul {list-style:none;display:flex;position:relative;}
#nav ul li {width: 50px;display:inline-table;padding: 10px 20px;position:relative;}
#nav ul li:hover {background:#333;}
#nav ul li:hover > ul {display: block;position:absolute;margin-left:0px;width:100%;}
#nav ul li a{text-decoration:none;font-family:Verdana;color:#fff;}
#nav ul ul {display:none;}
#nav ul ul li {background: #008080;}

My problem is :

  • My css drop down is not aligning with the li element.

Can anyone help me out ?

CSS Dropdown

1
  • add padding to anchors not to list check my update Commented Sep 7, 2014 at 10:14

4 Answers 4

2

Try this one, there was a "padding" on your submenu list

#nav ul li:hover > ul {
     display: block;
     position:absolute;
     left:0px;
     width:100%;
     padding-left:0px;
}
Sign up to request clarification or add additional context in comments.

Comments

2

use negative margin value http://jsfiddle.net/5tz0zszy/

I've made a bit change in the css

#nav {
background: #008080;
position:relative;
}
#nav ul {
list-style:none;
display:flex;
position:relative;
}
#nav ul li {
width: 50px;
display:inline-table;
padding: 10px 20px;
position:relative;
}
#nav ul li:hover {
background:#333;
}
#nav ul li:hover > ul {
display: block;
position:absolute;
margin-left:-60px;width:100%;
}
#nav ul li a{
text-decoration:none;
font-family:Verdana;
color:#fff;
}
#nav ul ul {
display:none;
}
#nav ul ul li {
background: #008080;
} 

Comments

2

RESET YOUR CSS *{box-sizing:border-box;padding:0; margin:0;}

add padding to anchors not to list

DEMO

*{box-sizing:border-box;padding:0; margin:0;}
#nav {background: #008080;position:relative;}
#nav ul {display:flex;position:relative;}
#nav ul li {list-style:none;float:left;position:relative;}
#nav ul li:hover {background:#333;}
#nav ul li > ul {position:absolute;}
#nav ul li:hover > ul {display: block;}
#nav a{text-decoration:none;font-family:Verdana;color:#fff;display:block;clear:both;padding: 10px 20px;}
#nav ul ul {display:none;position: absolute;left: 0;}
#nav ul ul li {background: #008080;display:block;width:100%;}

enter image description here

Comments

2

Simple add this:

#nav ul li:hover > ul {
    display: block;
    position:absolute;
    margin-left:0px;
    width:100%;
    left: 0;/*Add this*/
    padding: 0;/*Add this*/
    top: 40px;/*Add this*/
}

Also change to display: block #nav ul li {width: 50px;display:block;padding: 10px 20px;position:relative;}. Check resume menu.

fiddle

1 Comment

Yeah man thanks!! but I did top:100% :). Appriciate that though !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.