a busy cat http://i61.tinypic.com/2nu3ok3.jpg
I created a menu with jquery: div 1 for a main menu and div 2 for the submenu. When you hover the mouse over the item, the div 2 appears under the selected menu.
Can I make a menu more optimized?
Can you make a CSS menu on 2 lines with the function described in the image?
<div id="main-menu">
<ul>
<li><a href="#" class="category" rel="">Home</a></li>
<li><a href="#" class="category" rel="submenu1">test</a></li>
</ul>
</div>
<div id="menu-wrap">
<div id="menu">
<div id="submenu1" class="submenu">
<ul>
<li><a href="#">sub menu 1</a></li>
<li><a href="#">sub menu 2</a></li>
</ul>
</div>
</div>
</div>
is possible to realize the menu without the use of jquery but only CSS?
In order for this to work, the sub-menus will need to be nested (in the DOM) inside of their main-menu entries. We'll need to modify the HTML markup using lists.
A description of the code: we'll create a container for the whole thing, and float that right. After the container, we'll have a div that simply clears the float, so the rest of the page displays properly. Inside of the container, we'll have an unordered list for the main menu -- each list item will contain a link and an unordered list for the submenus. Those submenu lists will initially be
display:none
. We'll have to position the submenus absolutely, so that they appear below below the main menu instead of in the middle. Then the magic happens using the:hover
pseudo selector, and a nested selection: when a main-menu list item is hovered, it's childul
tag will be set todisplay:block
.HTML changes:
And the accompanying CSS:
See the live demo here.
This may need some tweaking to support legacy browsers, if that is a requirement. Some code (for hover effect) was sourced from the A List Apart Suckerfish CSS Dropdown Menu.