CSS Dropdown Menu issues
Posted
by Simon Hume
on Stack Overflow
See other posts from Stack Overflow
or by Simon Hume
Published on 2010-03-21T19:01:03Z
Indexed on
2010/03/21
19:11 UTC
Read the original article
Hit count: 1417
Can anyone help with a small problem.
I've got a nice simple CSS dropdown menu
http://www.cinderellahair.co.uk/new/CSSDropdown.html
The problem I have is when you rollover a menu item that has children which are wider than the content, it pushes the whole menu right.
Aside of shortening the child menu links down, is there any tweak I can make to my CSS to stop this happening?
CSS Code:
/* General */
#cssdropdown, #cssdropdown ul { list-style: none; }
#cssdropdown, #cssdropdown * { padding: 0; margin: 0; }
#cssdropdown {padding:43px 0px 0px 0px;}
/* Head links */
#cssdropdown li.headlink { margin:0px 40px 0px -1px; float: left; background-color: #e9e9e9;}
#cssdropdown li.headlink a { display: block; padding: 0px 0px 0px 5px; text-decoration:none; }
#cssdropdown li.headlink a:hover { text-decoration:underline; }
/* Child lists and links */
#cssdropdown li.headlink ul { display: none; text-align: left; padding:10px 0px 0px 0px; font-size:12px; float:left;}
#cssdropdown li.headlink:hover ul { display: block; }
#cssdropdown li.headlink ul li a { padding: 5px; height: 17px; }
#cssdropdown li.headlink ul li a:hover { background-color: #333; }
/* Pretty styling */
body { font-family:Georgia, "Times New Roman", Times, serif; font-size: 16px; }
#cssdropdown a { color: grey; } #cssdropdown ul li a:hover { text-decoration: none; }
#cssdropdown li.headlink { background-color: white; }
#cssdropdown li.headlink ul { padding-bottom: 10px;}
HTML:
<ul id="cssdropdown">
<li class="headlink"><a href="http://www.cinderellahair.co.uk/new/index.php">HOME</a></li>
<li class="headlink"><a href="http://www.cinderellahair.co.uk/new/gallery/gallery.php">GALLERY</a>
<ul>
<li><a href="http://amazon.com/">CELEBRITY</a></li>
<li><a href="http://ebay.com/">BEFORE & AFTER</a></li>
<li><a href="http://craigslist.com/">HAIR TYPES</a></li>
</ul>
</li>
<li class="headlink"><a href="http://www.cinderellahair.co.uk/new/about-cinderella-hair-extensions/about-us.php">ABOUT US</a>
<ul>
<li><a href="http://amazon.com/">WHY CHOOSE CINDERELLA</a></li>
<li><a href="http://ebay.com/">TESTIMONIALS</a></li>
<li><a href="http://craigslist.com/">MINI VIDEO CLIPS</a></li>
<li><a href="http://craigslist.com/">OUR HAIR PRODUCTS</a></li>
</ul>
</li>
<li class="headlink"><a href="http://www.cinderellahair.co.uk/new/news-and-offers/news.php">NEWS & OFFERS</a>
<ul>
<li><a href="http://amazon.com/">VERA WANG FREE GIVEAWAY</a></li>
<li><a href="http://ebay.com/">CINDERELLA ON TV</a></li>
<li><a href="http://craigslist.com/">CINDERELLA IN THE PRESS</a></li>
<li><a href="http://craigslist.com/">CINDRELLA NEWSLETTERS</a></li>
</ul>
</li>
<li class="headlink"><a href="http://www.cinderellahair.co.uk/new/cinderella-salon/salon-finder.php">SALON FINDER</a></li>
</ul>
JS Code:
$(document).ready(function(){
$('#cssdropdown li.headlink').hover(
function() { $('ul', this).css('display', 'block'); },
function() { $('ul', this).css('display', 'none'); });
});
Full code is on the link above, just view source.
© Stack Overflow or respective owner