Creating a Simple yet Stylish CSS Jquery Menu

Date: 27th Sep 2010 Author: admin 9 Comments
Posted in: HTML/CSS, jQuery |Tags: , , , , , ,

Creating a Simple yet Stylish CSS Jquery Menu

Currently, css menus are becoming more and more popular, which is not surprising. Small size, speed, ease to create. I want to introduce you to one very interesting and useful resource – http://www.cssplay.co.uk/. Here you can find tonns of really nice menus which you can use in your projects. Today I want to tell you how to enhance these menus using our library – jQuery.

Here are samples and downloadable package:

Live Demo
download in package

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

<script src="js/jquery.min.js"></script>
<script src="js/main.js"></script>
<link rel="stylesheet" href="templates/css/main.css" type="text/css" />

<div class="examples">

    <div id="menu">
        <ul class="level1">
            <li class="level1-li"><a class="level1-a" href="#url">Home</a></li>
            <li class="level1-li"><a class="level1-a drop" href="#url">Contact Us<!--[if gte IE 7]><!--></a><!--<![endif]-->
            <!--[if lte IE 6]><table><tr><td><![endif]-->
                <ul class="level2">
                    <li><a href="#url">Email</a></li>
                    <li><a href="#url">Telephone</a></li>
                    <li><a href="#url">Online Form</a></li>
                    <li><a href="#url">Snail Mail Address</a><b></b></li>
                </ul>
            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
            </li>
            <li class="level1-li"><a class="level1-a drop" href="#url">Resort<!--[if gte IE 7]><!--></a><!--<![endif]-->
            <!--[if lte IE 6]><table><tr><td><![endif]-->
                <ul class="level2">
                    <li><a href="#url">Ski Hire Facilities</a></li>
                    <li><a class="fly" href="#url">Main Ski Slopes<!--[if gte IE 7]><!--></a><!--<![endif]-->
                    <!--[if lte IE 6]><table><tr><td><![endif]-->
                        <ul class="level3">
                            <li><a href="#url">Beginners Slopes</a></li>
                            <li><a href="#url">Intermediate Slopes</a></li>
                            <li><a class="fly" href="#url">Advanced Skill Levels<!--[if gte IE 7]><!--></a><!--<![endif]-->
                            <!--[if lte IE 6]><table><tr><td><![endif]-->
                                <ul class="level4">
                                    <li><a href="#url">Local</a></li>

                                    <li><a href="#url">Nearby</a></li>
                                    <li><a href="#url">With instructor</a></li>
                                    <li><a href="#url">Snow boarding</a><b></b></li>
                                </ul>
                            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                            </li>
                            <li><a href="#url">Expert</a></li>
                        </ul>
                    <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                    </li>
                    <li><a href="#url">Night Life</a></li>
                    <li><a class="fly" href="#url">Restaurants<!--[if gte IE 7]><!--></a><!--<![endif]-->
                    <!--[if lte IE 6]><table><tr><td><![endif]-->
                        <ul class="level3">
                            <li><a href="#url">Snow Hotel</a></li>

                            <li><a href="#url">The Snowman</a></li>
                            <li><a href="#url">Ice Cavern</a></li>
                            <li><a href="#url">Ski Inn</a><b></b></li>
                        </ul>
                    <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                    </li>
                    <li><a class="fly" href="#url">Car Hire<!--[if gte IE 7]><!--></a><!--<![endif]-->
                    <!--[if lte IE 6]><table><tr><td><![endif]-->
                        <ul class="level3">
                            <li><a href="#url">From Airport</a></li>
                            <li><a href="#url">In Resort</a></li>
                            <li><a href="#url">Multiple Resorts</a><b></b></li>
                        </ul>
                    <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                    </li>
                </ul>
            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
            </li>
            <li class="level1-li"><a class="level1-a drop" href="#url">Surrounding Area<!--[if gte IE 7]><!--></a><!--<![endif]-->
            <!--[if lte IE 6]><table><tr><td><![endif]-->
                <ul class="level2">
                    <li><a href="#url">Where to go</a></li>

                    <li><a href="#url">What to do</a></li>
                    <li><a href="#url">Places of interest</a></li>
                    <li><a href="#url">National parks & Museums</a><b></b></li>
                </ul>
            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
            </li>
            <li class="level1-li left"><a class="level1-a drop" href="#url">Information<!--[if gte IE 7]><!--></a><!--<![endif]-->
            <!--[if lte IE 6]><table><tr><td><![endif]-->
                <ul class="level2">
                    <li><a href="#url">Money Exchange</a></li>
                    <li><a class="fly" href="#url">Resort Essential Information<!--[if gte IE 7]><!--></a><!--<![endif]-->
                    <!--[if lte IE 6]><table><tr><td><![endif]-->
                        <ul class="level3">
                            <li><a href="#url">Lift Passes</a></li>
                            <li><a href="#url">Insurance</a></li>
                            <li><a class="fly" href="#url">Gear Rental<!--[if gte IE 7]><!--></a><!--<![endif]-->
                            <!--[if lte IE 6]><table><tr><td><![endif]-->
                                <ul class="level4">
                                    <li><a href="#url">Boots</a></li>
                                    <li><a href="#url">Skis</a></li>
                                    <li><a href="#url">Ski Wear</a></li>
                                    <li><a href="#url">Goggles</a><b></b></li>
                                </ul>
                            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                            </li>
                            <li><a href="#url">Ski Schools</a></li>
                            <li><a href="#url">Snow Report</a></li>
                        </ul>
                    <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                    </li>
                    <li><a class="fly" href="#url">Language<!--[if gte IE 7]><!--></a><!--<![endif]-->
                    <!--[if lte IE 6]><table><tr><td><![endif]-->
                        <ul class="level3">
                            <li><a href="#url">Austrian</a></li>
                            <li><a href="#url">German</a></li>
                            <li><a href="#url">French</a></li>
                            <li><a href="#url">English</a><b></b></li>
                        </ul>
                    <!--[if lte IE 6]></td></tr></table></a><![endif]-->
                    </li>
                    <li><a href="#url">Short Breaks</a></li>
                </ul>
            <!--[if lte IE 6]></td></tr></table></a><![endif]-->
            </li>
            <li class="level1-li"><a class="level1-a" href="#url">Privacy</a></li>
        </ul>
    </div>

    <div style="clear:both"></div>
</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

$(document).ready(function(){
    $('#menu li').hover(function(){
            $(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(400); // effect 1
            // $(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400); // effect 2
        },function(){
            $(this).find('ul:first').css({visibility: "hidden"});
        });
});

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):

    snowboard.jpg
    white-down.gif
    white-left.gif
    white-right.gif

Live Demo
download in package

Conclusion

Today I 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 luck!

Enjoyed this Post?

    Tweet
   
   

Stay connected with us:

If you enjoyed this article, feel free to share our tutorial with your friends.

9 Comments

    • fred's Gravatar
    • TP's Gravatar
    • TB's Gravatar
    • Jijo's Gravatar
    • Hi Admin,

      The tutorial work perfectly fimr in chrome and firefox.
      However the hover thingy is somehow not working on internet explorer 8.

      Appreciate if you can let me know the fix.

      regards,
      Jijo

    • sundar's Gravatar
    • it’s not working in IE 8..
      Totally Dead..
      it’s working perfectly in IE 6,7 but not in IE8..
      can u give the solution for that?
      how to resolve it

    • Ali's Gravatar

Leave a Reply

Your email address will not be published. Required fields are marked *

*

CAPTCHA Image
Refresh Image

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>