MS Office-Style CSS3 Multilevel Menu
Join the DZone community and get the full member experience.
Join For Freein our new tutorial i will give you another brilliant crossbrowser css3 navigation menu. this is a click action drop down menu with strict office styles (like ms office styles). you can also use different icons in this menu. this solution is ideal for business websites. if you are ready, let's start.
this is our final result:
here are the samples and downloadable package:
live demo
download in package
ok, download the sources and let's start coding !
step 1. html
pleasedirect your attention to the html layout of our multilevel menu. this is the usual ul-li based multilevel navigation menu. of course, the most interesting thing is the css styles.
index.html
<div id="nav"> <ul> <li><span tabindex="1">file</span> <ul> <li><a href="#"><img src="images/icon1.gif" alt="" />new</a></li> <li><a href="#"><img src="images/icon2.gif" alt="" />open</a></li> <li><a href="#"><img src="images/icon3.gif" alt="" />close</a></li> <li><span tabindex="1"><img src="images/icon4.gif" alt="" />save</span> <ul> <li><span tabindex="1"><img src="images/icon4.gif" alt="" />option 1</span> <ul> <li><a href="#"><img src="images/icon1.gif" alt="" />option a</a></li> <li><a href="#"><img src="images/icon2.gif" alt="" />option b</a></li> <li><a href="#"><img src="images/icon3.gif" alt="" />option c</a></li> </ul> </li> <li><a href="#"><img src="images/icon2.gif" alt="" />option 2</a></li> <li><a href="#"><img src="images/icon3.gif" alt="" />option 3</a></li> </ul> </li> <li><a href="#"><img src="images/icon5.gif" alt="" />save as</a></li> <li><a href="#"><img src="images/icon1.gif" alt="" />print</a></li> <li><a href="#"><img src="images/icon2.gif" alt="" />exit</a></li> </ul> </li> <li><span tabindex="1">edit</span> <ul> <li><a href="#"><img src="images/icon1.gif" alt="" />cut</a></li> <li><a href="#"><img src="images/icon2.gif" alt="" />copy</a></li> <li><a href="#"><img src="images/icon3.gif" alt="" />paste</a></li> </ul> </li> <li><span tabindex="1">view</span> <ul> <li><a href="#"><img src="images/icon1.gif" alt="" />normal</a></li> <li><a href="#"><img src="images/icon2.gif" alt="" />web layout</a></li> <li><a href="#"><img src="images/icon3.gif" alt="" />print layout</a></li> </ul> </li> <li><a href="#">insert</a></li> <li><a href="#">format</a></li> <li><a href="#">tools</a></li> <li><a href="#">table</a></li> <li><a href="#">window</a></li> <li><a href="http://www.script-tutorials.com/">help</a></li> <img class="close" src="images/spacer.gif" alt="" /> </ul> </div>
step 2. css
here are the css styles of our click action dropdown menu.
css/menu.css
#nav { position:relative; z-index:2; } #nav ul { background-color:#b8d1f8; border:1px solid #000c80; height:24px; list-style:none outside none; margin:0; padding:1px; } #nav ul ul { background-color:#ffffff; border:1px solid #8a867a; display:none; height:auto; left:0; padding:0; position:absolute; top:25px; width:168px; background-image:-webkit-gradient(left center , #f8faff 0%, #b8d1f8 15%, #ffffff 15%, #ffffff 100%); background-image:-moz-linear-gradient(left center , #f8faff 0%, #b8d1f8 15%, #ffffff 15%, #ffffff 100%); } #nav ul ul ul { display:none; left:168px; position:absolute; top:-1px; width:168px; } #nav ul li { float:left; margin-right:1px; position:relative; } #nav ul li a { border:1px solid #b8d1f8; color:#000; cursor:default; display:block; font:11px tahoma,arial; padding:3px 3px 4px; text-decoration:none; } #nav ul li span { background:url("../images/u.gif") no-repeat scroll 90% center transparent; border:1px solid #b8d1f8; color:#000; cursor:default; display:block; font:11px tahoma,arial; padding:3px 14px 4px 3px; position:relative; } #nav ul ul li span { background:url("../images/s.gif") no-repeat scroll 97% center transparent; } #nav ul ul li { float:none; margin-right:0; padding:1px; text-indent:10px; } #nav ul ul li a,#nav ul ul li span { border:1px solid transparent; padding:3px 3px 5px 2px; } #nav ul ul li a img,#nav ul ul li span img { border-width:0; float:left; margin-right:5px; vertical-align:middle; } #nav ul li:hover > a,#nav ul li:hover > span { background-color:#fff2c8; border:1px solid #000c80; color:#000; } #nav img.close { display:none; height:100%; left:0; position:fixed; top:0; width:100%; z-index:-1; } #nav ul li span:focus + ul,#nav ul li ul:hover,#nav ul:hover + img.close { display:block; }
less than 100 lines of code. it’s great, isn’t it?
live demo
download in package
conclusion
hope you enjoyed with our new css3 menu! don’t forget to tell your thanks and leave a comment
good luck!
Published at DZone with permission of Andrey Prikaznov, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments