John Smith
John Smith

Reputation: 6197

How to add "submenus" to this slide-menu?

I got a design:

http://jsfiddle.net/WS3QQ/

<div id="topmenu"><ul>
<li><a href="/">menu1</a></li>
<li><a href="/">menu2</a></li>
<li><a href="/">menu3</a></li>
<li><a href="/">menu4</a></li>
</ul>
<div style="clear: both;"></div>
</div>

#topmenu
{
    margin-top: 20px;
    min-height: 47px;
    background-color: green;
}

#topmenu ul
{
    list-style-type: none;
    margin: 0 0 0 0;
    padding: 13px 0 0 0;
    color: #fff;
    font-size: 1.6em;
}

#topmenu ul li
{
    display: inline;
    padding: 15px 2.5% 17px 2.5%;
    margin: 0 0 0 0;
}

#topmenu ul li:last-child
{
    border: none;
    box-shadow: none;
}

#topmenu ul li:first-child
{
    border-top-left-radius: 15px;
}

#topmenu ul li img
{
    vertical-align: middle;
}

#topmenu ul li:hover
{
    background-color: yellow;
}

now I want to do a sub menu under "menu3" but I have absolutely no idea how to do this. I didnt wrote this basic-design, Im not even a sitebuilder....

Upvotes: 0

Views: 488

Answers (1)

misterManSam
misterManSam

Reputation: 24692

I have created a really simple implementation of this. It is barebones so that you can get a real easy look at the basic concept.

In the fiddle here: http://jsfiddle.net/WS3QQ/2/

HTML - Note how the sub-menus are nested

<div id="nav">
<ul>
    <li><a href="#">Top Menu</a>
        <ul>
            <li><a href="#">Sub-Menu</a></li>
            <li><a href="#">Sub-Menu</a></li>
            <li><a href="#">Sub-Menu</a></li>
        </ul>       
    </li>
    <li><a href="#">Top Menu</a></li>
    <li><a href="#">Top Menu</a></li>
    <li><a href="#">Top Menu</a></li>
</ul>
</div>

CSS - note how you can easily target the sub-menus (#nav li li). By default the sub-menu li is hidden (display:none). When the li is hovered over, the sub menu li is shown (display:block).

#nav ul { list-style-type: none; margin: 0; padding: 0; }
#nav li { float: left; } 
#nav li li { clear: left; display: none; }
#nav li:hover li { display: block; }
#nav li:hover a { background: #111; }
#nav li a { background: #333; padding: 10px; display: block; color: #FFF; font-weight: bold; text-decoration: none; }
#nav li a:hover { background: #3914AF; }

Upvotes: 1

Related Questions