Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Simple responsive menu using css3

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 488
    Comment on it

    Hello readers !
    This blog is about how to make a simple navigation menu .
    First of all you need an unorder listing(ul-li) in html page as I have taken in example below.
    Now remember you also need an anchor tag after list.
    The anchor tag will not show in full width ,it works only when you decrease your view screen size.

    After this we come on css.
    Here we define all classes with their attributes. Also you can manage media screen width as per your needs.

    Now the last and important step you need add javascript to hide and show last anchor tag.
    Hope It will help you.
    Note:- You have to include jquery library aslo.

    <-- Html -->

    <nav class="clearfix">
      <ul class="clearfix">
        <li><a href="#">Nav Tital</a></li>
        <li><a href="#">Nav Tital</a></li>
        <li><a href="#">Nav Tital</a></li>
        <li><a href="#">Nav Tital</a></li>
        <li><a href="#">Nav Tital</a></li>
        <li><a href="#">Nav Tital</a></li>
      </ul>
      <a href="#" id="gear">Navigation</a>
    </nav>
    

    <--css-->

    * {
        margin: 0px;
        text-decoration: none;
        padding: 0px
    }
    .clearfix:before, .clearfix:after {
        content: " ";
        display: table;
    }
    .clearfix:after {
        clear: both;
    }
    .clearfix {
     *zoom: 1;
    }
    body {
        background: #e5e5e5;
        font-family: Arial, sans-serif;
    }
    nav {
        height: 40px;
        background: #999;
        font-size: 13px;
        position: relative;
        font-weight: bold;
    }
    nav ul {
        margin: 0 auto;
        width: 600px;
    }
    nav li {
        display: inline;
        float: left;
    }
    nav a {
        color: #fff;
        display: inline-block;
        width: 100px;
        text-align: center;
        line-height: 40px;
    }
    nav li a {
        border-right: 1px solid #333;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
    }
    nav li:last-child a {
        border-right: 0;
    }
    nav a:hover, nav a:active {
        background: #666666;
    }
    nav a#gear {
        display: none;
    }
     @media screen and (max-width:599px) {
    nav {
        height: auto;
    }
    nav ul {
        width: 100%;
        display: block;
        height: auto;
    }
    nav li {
        width: 50%;
        float: left;
        position: relative;
    }
    nav li a {
        border-bottom: 1px solid #333333;
        border-right: 1px solid #333333;
    }
    nav a {
        text-align: left;
        width: 100%;
        text-indent: 25px;
    }
    }
     @media only screen and (max-width : 479px) {
    nav {
        border-bottom: 0;
    }
    nav ul {
        display: none;
        height: auto;
    }
    nav a#gear {
        display: block;
        background-color: #222;
        width: 100%;
        position: relative;
    }
    nav a#gear:after {
        content: "";
        background: url('navigationICON.png') no-repeat; /* This is the path of image */
        width: 30px;
        height: 30px;
        display: inline-block;
        position: absolute;
        right: 15px;
        top: 10px;
    }
    }
     @media only screen and (max-width : 320px) {
    nav li {
        display: block;
        float: none;
        width: 100%;
    }
    nav li a {
        border-bottom: 1px solid #333;
    }
    }
    

    <--Script-->

    <script>
            $(function() {
                var gear        = $('#gear');
                    menu        = $('nav ul');
                    menuHeight  = menu.height();
    
                $(gear).on('click', function(e) {
                    e.preventDefault();
                    menu.slideToggle();
                });
    
            });
        </script>
    

    You have to include this :-

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: