Reputation: 13206
How would I line up my dropdown elements with the clicker?
Here is my CSS code
#header_dropdown {
float: right;
}
.click-nav {
width: 200px;
}
.click-nav ul {
position: relative;
}
.click-nav ul li {
position: relative;
list-style: none;
cursor: pointer;
}
.click-nav ul li ul {
position: absolute;
}
.click-nav ul .clicker {
position: relative;
background: #2284B5;
color: #FFF;
}
.click-nav ul .clicker:hover, .click-nav ul .active {
background: #196F9A;
}
.click-nav ul li a {
transition: background-color 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out;
-moz-transition: background-color 0.2s ease-in-out;
display: block;
background: #FFF;
color: #333;
text-decoration: none;
}
.click-nav ul li a:hover {
background: #F2F2F2;
}
/* Fallbacks */
.click-nav .no-js ul {
display: none;
}
.click-nav .no-js:hover ul {
display: block;
}
Jsfiddle at http://jsfiddle.net/KVrFM/
Upvotes: 0
Views: 49
Reputation: 21695
You need to remove the padding from the sub-menu ul
.
I modified your anonymous function to add the active class to the li
rather than the anchor tag using jQuery parent()
.
$('.clicker').parent().toggleClass('active');
Then I added the following CSS rule. When doing drop-down and fly-out menus in CSS it is helpful to use the child combinator >
. Having a rule like .click-nav ul
will target all ul
that are descendants of .click-nav
. Changing that rule to .click-nav > ul
will only target ul
s that are children of .click-nav
and not grandchildren etc.
.active ul {
padding: 0;
}
Upvotes: 1