Skip to content Skip to sidebar Skip to footer

Drop Down Menu - JQuery/CSS

I have a problem with a dropdown menu I am doing. Please check this screenshot out: http://img215.imageshack.us/img215/8449/hovermenu.png This is the html code:
    /* CSS RESET */
    * { margin: 0; padding: 0; }
    
    body { background: #19192b; }
    .topnav {
        float: left;
        font-family: Verdana;
        font-size: 11px;
        margin: 9px;
        padding: 0;
        list-style-type: none; }
    .topnav a { 
        color: #333;
        text-align: center;
        text-decoration: none;
        height: 14px; /* 34 - 20 */
        padding: 10px 15px;
        cursor: pointer;
        display: block; }
    /* First child */
    .topnav > li {
        position: relative;
        background: #f0f0f0 url(../images/topmenubg.png) 0 0 repeat-x;
        float: left;
        border: 0 solid #d9d9d9;
        border-width: 0 0 0 1px;
        display: block; }
    .topnav > li:hover { background: #d9d9d9; }
    .topnav > li:first-child { 
        -moz-border-radius: 16px 0 0 16px;
        -webkit-border-radius: 16px 0 0 16px;
        border-radius: 16px 0 0 16px;
        border-left: 0; }
    .topnav > li:last-child { 
        -moz-border-radius: 0 16px 16px 0;
        -webkit-border-radius: 0 16px 16px 0;
        border-radius: 0 16px 16px 0; }
    .topnav > li:first-child a { padding-left: 20px; }
    .topnav > li:last-child a { padding-right: 20px; }
    .topnav li ul { 
        position: absolute;
        top: 34px;
        width: 100%;
        display: none; }
    .topnav li:hover ul { display: block; }
    .topnav li ul li {
        background: #f0f0f0;
        font-size: 10px;
        padding: 1px 0 0;
        border-top: 1px solid #d9d9d9;
        display: block; }
    .topnav li ul li:hover { background: #fff; }
    .topnav li ul li:last-child {
        -moz-border-radius: 0 0 16px;
        -webkit-border-radius: 0 0 16px;
        border-radius: 0 0 16px 16px;}
    .topnav li ul li a {
        width: 100%;
        padding: 10px 0;
        height: auto; }
    .topnav li ul li:last-child a { padding-bottom: 18px; }
    

    Here's a fiddle with a working example (no javascript): http://jsfiddle.net/MFmwJ/


Solution 2:

Use DROPPY to make dropdown menus easily. No css or extra javascript is required.

See this example:

<link  href="http://onehackoranother.com/projects/jquery/droppy/s/droppy.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"/></script>
<script src="http://onehackoranother.com/projects/jquery/droppy/javascripts/jquery.droppy.js"/></script>

<ul class="topnav">
<li><a href="#">Home</a></li>
<li>
    <a href="#" class="subnavkey">Tutorials</a>
    <ul class="subnav">
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
    </ul>
</li>
<li>
    <a href="#" class="subnavkey">Resources</a>
    <ul class="subnav">
        <li><a href="#">Sub Nav Link</a></li>
        <li><a href="#">Sub Nav Link</a></li>
    </ul>
</li>
<li><a href="#">About Us</a></li>
<li><a href="#">Advertise</a></li>
<li><a href="#">Submit</a></li>
<li><a href="#">Contact Us</a></li>

$(function () {
    $('.topnav').droppy();
});

http://jsfiddle.net/AtbK5/

Droppy: http://onehackoranother.com/projects/jquery/droppy/


Solution 3:

I guess you sub menu list items (li) also are floated, clear them.


Solution 4:

try this:

$(document).ready(function(){
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    $(".subnavkey").hover(
        function() { //When trigger is clicked...
            //Following events are applied to the subnav itself (moving subnav up and down)
            $(this).addClass("subhover").parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
        }
        , function(){
            $(this).removeClass("subhover").parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
        }
    );
});

Post a Comment for "Drop Down Menu - JQuery/CSS"