Reputation: 15
Need some help with a drop down menu.
I made a fiddle here: http://jsfiddle.net/bLL0rmbd/
I want to align the hover submenu like in the image:
HTML:
<div id="wrapper">
<div id="navbar">
<ul>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a>
<ul>
<li><a href="#">SubMenu 1</a></li>
<li><a href="#">SubMenu 2</a></li>
<li><a href="#">SubMenu 3</a></li>
</ul>
</li>
</ul>
</div>
</div>
CSS:
<style>
#wrapper {padding: 0; margin: 30px}
#navbar ul {
padding: 0;
margin:0px;
list-style: none;
float:left;
background:#FF6;
}
#navbar ul li { display: inline-block; margin-right:20px;}
#navbar ul li a {text-decoration:none;}
#navbar ul ul {
position:absolute;
display: none;
}
#navbar ul ul li {display:block;}
#navbar ul li:hover > ul {
display: block;
background-color:#CFC;
}
</style>
Upvotes: 1
Views: 91
Reputation: 1834
#navbar ul {
padding: 0;
margin:0px;
list-style: none;
float:left;
background:#FF6;
position: relative;
}
#navbar ul ul {
position:absolute;
display: none;
right: 0;
top: 100%;
}
Upvotes: 0
Reputation: 1485
Add this CSS style for your recent question:
li:hover{background-color:#CFC;}
#navbar ul li:hover > ul
{ display: block;
background-color:#CFC;
margin-left:-25px;
}
Check Out this fiddle:http://jsfiddle.net/bLL0rmbd/11/
Upvotes: 0
Reputation: 4637
You this css here
#navbar ul {
padding: 0;
margin:0px;
float:left;
background:#CFC;
position: relative;
}
#navbar ul ul {
position:absolute;
display: none;
right: 0;
top: 100%;
}
Upvotes: 0
Reputation: 404
i hope this works for you .
#navbar ul {
padding: 0;
margin:0px;
list-style: none;
float:left;
background:#FF6;
position: relative;
}
#navbar ul ul {
position:absolute;
display: none;
right: 0;
top: 100%;
}
I have only aded 3 lines of code pos: relative on ul and absolute value on dropdown.
Or you can set pos: relative to #navbar li and change absolute value for dropdown accrding to wish.
Cheers
Upvotes: 1
Reputation: 9452
Add a negative margin-left
to the sub menu and it should work:
#navbar ul li:hover > ul
{ display: block;
background-color:#CFC;
margin-left:-25px;
}
Updated fiddle:http://jsfiddle.net/bLL0rmbd/3/
Upvotes: 0