Nowadays, css menus are becoming more and more popular, which is not surprising. Small size, fast speed, ease to create. In today’s tutorial I will tell you how to create a stylish navigation menu using not only CSS, but also jQuery library. It can help us enhance the default behavior. If you are ready – we can start.
Here are samples and downloadable package:
Live Demo
[sociallocker]
download in package
[/sociallocker]
Ok, download the example files and lets start coding !
Step 1. HTML
As usual, we start with the HTML.
This is our main page code.
index.html
001 |
< script src = "js/jquery.min.js" ></ script > |
002 |
< script src = "js/main.js" ></ script > |
003 |
< link rel = "stylesheet" href = "templates/css/main.css" type = "text/css" /> |
004 |
< div class = "examples" > |
005 |
< div id = "menu" > |
006 |
< ul class = "level1" > |
007 |
< li class = "level1-li" >< a class = "level1-a" href = "#url" >Home</ a ></ li > |
008 |
< li class = "level1-li" >< a class = "level1-a drop" href = "#url" >Contact Us <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
009 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
010 |
< ul class = "level2" > |
011 |
< li >< a href = "#url" >Email</ a ></ li > |
012 |
< li >< a href = "#url" >Telephone</ a ></ li > |
013 |
< li >< a href = "#url" >Online Form</ a ></ li > |
014 |
< li >< a href = "#url" >Snail Mail Address</ a >< b ></ b ></ li > |
015 |
</ ul > |
016 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
017 |
</ li > |
018 |
< li class = "level1-li" >< a class = "level1-a drop" href = "#url" >Resort <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
019 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
020 |
< ul class = "level2" > |
021 |
< li >< a href = "#url" >Ski Hire Facilities</ a ></ li > |
022 |
< li >< a class = "fly" href = "#url" >Main Ski Slopes <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
023 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
024 |
< ul class = "level3" > |
025 |
< li >< a href = "#url" >Beginners Slopes</ a ></ li > |
026 |
< li >< a href = "#url" >Intermediate Slopes</ a ></ li > |
027 |
< li >< a class = "fly" href = "#url" >Advanced Skill Levels <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
028 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
029 |
< ul class = "level4" > |
030 |
< li >< a href = "#url" >Local</ a ></ li > |
031 |
< li >< a href = "#url" >Nearby</ a ></ li > |
032 |
< li >< a href = "#url" >With instructor</ a ></ li > |
033 |
< li >< a href = "#url" >Snow boarding</ a >< b ></ b ></ li > |
034 |
</ ul > |
035 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
036 |
</ li > |
037 |
< li >< a href = "#url" >Expert</ a ></ li > |
038 |
</ ul > |
039 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
040 |
</ li > |
041 |
< li >< a href = "#url" >Night Life</ a ></ li > |
042 |
< li >< a class = "fly" href = "#url" >Restaurants <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
043 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
044 |
< ul class = "level3" > |
045 |
< li >< a href = "#url" >Snow Hotel</ a ></ li > |
046 |
< li >< a href = "#url" >The Snowman</ a ></ li > |
047 |
< li >< a href = "#url" >Ice Cavern</ a ></ li > |
048 |
< li >< a href = "#url" >Ski Inn</ a >< b ></ b ></ li > |
049 |
</ ul > |
050 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
051 |
</ li > |
052 |
< li >< a class = "fly" href = "#url" >Car Hire <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
053 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
054 |
< ul class = "level3" > |
055 |
< li >< a href = "#url" >From Airport</ a ></ li > |
056 |
< li >< a href = "#url" >In Resort</ a ></ li > |
057 |
< li >< a href = "#url" >Multiple Resorts</ a >< b ></ b ></ li > |
058 |
</ ul > |
059 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
060 |
</ li > |
061 |
</ ul > |
062 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
063 |
</ li > |
064 |
< li class = "level1-li" >< a class = "level1-a drop" href = "#url" >Surrounding Area <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
065 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
066 |
< ul class = "level2" > |
067 |
< li >< a href = "#url" >Where to go</ a ></ li > |
068 |
< li >< a href = "#url" >What to do</ a ></ li > |
069 |
< li >< a href = "#url" >Places of interest</ a ></ li > |
070 |
< li >< a href = "#url" >National parks & Museums</ a >< b ></ b ></ li > |
071 |
</ ul > |
072 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
073 |
</ li > |
074 |
< li class = "level1-li left" >< a class = "level1-a drop" href = "#url" >Information <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
075 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
076 |
< ul class = "level2" > |
077 |
< li >< a href = "#url" >Money Exchange</ a ></ li > |
078 |
< li >< a class = "fly" href = "#url" >Resort Essential Information <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
079 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
080 |
< ul class = "level3" > |
081 |
< li >< a href = "#url" >Lift Passes</ a ></ li > |
082 |
< li >< a href = "#url" >Insurance</ a ></ li > |
083 |
< li >< a class = "fly" href = "#url" >Gear Rental <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
084 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
085 |
< ul class = "level4" > |
086 |
< li >< a href = "#url" >Boots</ a ></ li > |
087 |
< li >< a href = "#url" >Skis</ a ></ li > |
088 |
< li >< a href = "#url" >Ski Wear</ a ></ li > |
089 |
< li >< a href = "#url" >Goggles</ a >< b ></ b ></ li > |
090 |
</ ul > |
091 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
092 |
</ li > |
093 |
< li >< a href = "#url" >Ski Schools</ a ></ li > |
094 |
< li >< a href = "#url" >Snow Report</ a ></ li > |
095 |
</ ul > |
096 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
097 |
</ li > |
098 |
< li >< a class = "fly" href = "#url" >Language <!--[if gte IE 7]><!--> </ a > <!--<![endif]--> |
099 |
<!--[if lte IE 6]><table><tr><td><![endif]--> |
100 |
< ul class = "level3" > |
101 |
< li >< a href = "#url" >Austrian</ a ></ li > |
102 |
< li >< a href = "#url" >German</ a ></ li > |
103 |
< li >< a href = "#url" >French</ a ></ li > |
104 |
< li >< a href = "#url" >English</ a >< b ></ b ></ li > |
105 |
</ ul > |
106 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
107 |
</ li > |
108 |
< li >< a href = "#url" >Short Breaks</ a ></ li > |
109 |
</ ul > |
110 |
<!--[if lte IE 6]></td></tr></table></a><![endif]--> |
111 |
</ li > |
112 |
< li class = "level1-li" >< a class = "level1-a" href = "#url" >Privacy</ a ></ li > |
113 |
</ ul > |
114 |
</ div > |
115 |
< div style = "clear:both" ></ div > |
116 |
</ div > |
Step 2. CSS
Here are used CSS styles.
templates/css/main.css
Quite all css code is belong to css menu. I don`t including this into article. It always available in download package
Step 3. JS
Here are necessary JS file to our project.
js/main.js
1 |
$(document).ready( function (){ |
2 |
$( '#menu li' ).hover( function (){ |
3 |
$( this ).find( 'ul:first' ).css({visibility: "visible" ,display: "none" }).fadeIn(400); // effect 1 |
4 |
// $(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400); // effect 2 |
5 |
}, function (){ |
6 |
$( this ).find( 'ul:first' ).css({visibility: "hidden" }); |
7 |
}); |
8 |
}); |
You can play with effects – try to use fadeIn and slideDown. Both looks fine.
js/jquery.min.js
This is just jQuery library. No need to give full code of that file here. It always available in download package
Step 4. Images
Also we need several images for our demo (these images for menu):
Live Demo
Conclusion
Today I have told you how you can make any css menus more attractive and user friendly. You can use this material as is in your startups. Good