Simple Responsive Menu


Hi Today i am going to tell how to create a Simple Responsive Menu Using css3 media screen and jquery, Now a days all are doing Responsive website, That means to fix all the contents in all the screens like tab and mobile and desktop, laptop.

Now a days Lot of people using internet through Mobile and Tabs , So that only the Responsive concept has been implemented.

The Responsive Templates helps the customers to access the contents very easily because the contents and website are fixed the the particular screen no need to scroll left and right. so that the menu is very important to website so we will see how to create simple responsive menu using css and jquery.

Now we can see how to create Responsive Menu Using Jquery and css media screen

Responsive Design view press ctrl+Shift+M in Mozilla Firefox.





index.html

<!doctype html>
<html lang=''>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="script.js"></script>
<title>simple responsive menu | san web corner</title>
</head>
<body>
<div class="san">
<div id='sanmenu'>
<ul>
<li class='active'><a href='#'><span>About</span></a></li>
<li><a href='#'><span>Partners</span></a></li>
<li><a href='#'><span>Career</span></a>  </li>
<li><a href='#'><span>Location</span></a></li>
<li class='last'><a href='#'><span>News</span></a></li>
<li class='last'><a href='#'><span>Welbeing</span></a></li>
</ul>
</div>
</div>
</body>
<html>

styles.css

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,600,300);
#sanmenu {
    font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, Sans-Serif;
    font-size: 16px;
    line-height: 15px;
    text-align: center;
}
#sanmenu > ul {
    width: auto;
    list-style-type: none;
    padding: 0;
    margin: 0;
    background: #ffffff;
    border: 1px solid #ece6e8;
    border-bottom: 3px solid #d9ced2;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    -o-border-radius: 2px;
    border-radius: 2px;
}
.san {
    width: 70%;
    height: auto;
    margin-left: auto;
    margin-right: auto;
}
#sanmenu > ul li#responsive-tab {
    display: none;
    /* Hide for large screens */
}
#sanmenu > ul li {
    display: inline-block;
    *display: inline;
    zoom: 1;
}
#sanmenu > ul li.right {
    float: right;
}
#sanmenu > ul li.has-sub {
    position: relative;
}
#sanmenu > ul li.has-sub:hover ul {
    display: block;
}
#sanmenu > ul li.has-sub ul {
    display: none;
    width: 250px;
    position: absolute;
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: #ffffff;
    border: 1px solid #ece6e8;
    border-bottom: 3px solid #d9ced2;
    border-top: 0 none;
}
#sanmenu > ul li.has-sub ul li {
    display: block;
}
#sanmenu > ul li.has-sub > a {
    background-image: url('images/caret.png');
    background-repeat: no-repeat;
    background-position: 90% -95%;
}
#sanmenu > ul li.has-sub > a.active,
#sanmenu > ul li.has-sub > a:hover {
    background: #d80041 url('images/caret.png') no-repeat;
    background-position: 90% 195%;
}
#sanmenu > ul li a {
    display: block;
    padding: 12px 24px 11px 24px;
    text-decoration: none;
    color: #000;
    text-shadow: 0px 1px 0px #fff;
}
#sanmenu > ul li a.active,
#sanmenu > ul li a:hover {
    background: #d80041;
    color: #fff;
    text-shadow: 0px 1px 0px #000;
}
@media (max-width: 600px) {
    #sanmenu > ul {
        width: 100%;
    }
    #sanmenu > ul li#responsive-tab {
        display: block;
    }
    #sanmenu > ul li#responsive-tab a {
        background: url('images/menu.png') no-repeat;
        background-position: 95% -35%;
    }
    #sanmenu > ul li#responsive-tab a:hover {
        background-color: #d80041;
        background-position: 95% 135%;
    }
    #sanmenu > ul li {
        display: none;
    }
    #sanmenu > ul li.right {
        float: none;
    }
    #sanmenu > ul li.has-sub {
        position: relative;
    }
    #sanmenu > ul li.has-sub ul {
        display: block;
        position: static;
        width: 100%;
        background: #ffffff;
        border: 0 none;
    }
    #sanmenu > ul li.has-sub ul li {
        display: block !important;
    }
    #sanmenu > ul li.has-sub ul li a span {
        display: block;
        padding-left: 24px;
    }
    #sanmenu > ul li.has-sub > a {
        background-image: none;
    }
}
/* Make sure they show even if hidden in mobile view by JS */

@media (min-width: 600px) {
    #sanmenu > ul > li.collapsed {
        display: inline-block !important;
        *display: inline;
        zoom: 1;
    }
    #sanmenu > ul ul li.collapsed {
        display: block !important;
    }
}

Script.js

( function( $ ) {
$( document ).ready(function() {
// Cache the elements we'll need
var menu = $('#sanmenu');
var menuList = menu.find('ul:first');
var listItems = menu.find('li').not('#responsive-tab');

// Create responsive trigger
menuList.prepend('<li id="responsive-tab"><a href="#">Menu</a></li>');

// Toggle menu visibility
menu.on('click', '#responsive-tab', function(){
listItems.slideToggle('fast');
listItems.addClass('collapsed');
});
});
} )( jQuery );




I hope This post is very Helpful to you...................... 



Post a Comment

0 Comments