Navigation BarTutorials

How to create a responsive navigation bar – 01

How to create a responsive navigation bar ?

Before We Start

How to create a responsive navigation bar ? A navigation bar is one of the main components of a website,It contains links to the other sections and a user interface element within a website. The most important one and the first section that the user sees when he/she enters a website is the navigation bar and it links to the other main parts.

In a website the navigation bar will be an important part and it helps the users to find the pages quickly If you have ever seen a website which doesn’t has a navigation bar, you may have found it’s not easy to locate the exact page what you need. So if you are a person who wishes to develop a website, you have to know how to create a navigation bar properly.

Download Premium Plugins & Templates from Template Cafe

How to create a responsive navigation bar ? We are here to solve your problem.
In this article we discuss how to create a responsive navigation bar. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag.

<html>
<body>
<main class="container">
        <header>
          <nav class="navbar-menu">
            
            <!-- Menu normal -->
            <ul class="menu">
              <li><a>Home</a>
              </li><li><a>Menu 1</a>
                <!--<ul class="submenu two">
                  <li><a>Submenu 1</a></li>
                  <li><a>Submenu 2</a></li>
                </ul>-->
              </li><li><a>Menu 2</a>
                <ul class="submenu three">
                  <li><a>Submenu 1</a></li>
                  <li><a>Submenu 2</a></li>
                </ul>
              </li><li><a>Menu 3</a>
                
            </ul>
            
            <!-- sub Menu -->
            <nav class="navbar-mini-menu">
              <div class="menu-select">
                <span class="menu-actual">
                  Menu
                </span>
                <span class="btn-select">
                  
                </span>
              </div>
              <ul class="mini-menu-options">
                <li><a>Home</a></li>
                <li tabIndex="0"><a>Menu 1</a></li>
                <li tabIndex="0"><a>Menu 2</a>
                  <ul class="submenu five">
                    <li><a>Submenu 1</a></li>
                    <li><a>Submenu 2</a></li>
                  </ul>
                </li>
                <li tabIndex="0"><a>Menu 3</a></li>
                <li tabIndex="0"><a>About</a>
                  <ul class="submenu five">
                    <li><a>Contact me</a></li>
                    <li><a>About me</a></li>
                  </ul>
                </li>
                
              </ul> 
            </nav> 
            
          </nav>
        </header>
      </main>
</body>
</html>



Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag.

<style>
* {
  margin: 0;
  padding: 0;
}
body, html {
  font-family: segoe ui;
  font-size: 100%;
  height: 100%;
}
.container {
  background: #FFF;
  min-height: 100%;
  overflow: auto;
}
a {
  color: #fff;
  cursor: pointer;
  display: block;
  padding: 1rem 1.5rem;
  text-decoration: none;
  transition: background-color .16s ease-in;
}
a:hover {
  background-color: rgb(13, 218, 183);
}
.navbar-menu {
  background-color: rgb(18, 170, 184);
  margin: 2% auto;
  max-width: 1000px;
  width: calc(100%);
}
/* Menu */
.navbar-menu .menu {
  display: block;
  text-align: center;
}
/* List items*/
.navbar-menu .menu li {
  display: inline-block;
}
.navbar-menu .menu li:hover > .submenu {
  display: block;
  -webkit-animation-name: showSubMenu;
  -webkit-animation-duration: .4s;
}
.navbar-menu .menu li ul {
  background-color: #08beb5;
  display: none;
  position: absolute;
}
.navbar-menu .menu li ul li {
  display: block;
}
.navbar-menu .menu li ul li a:active {
  -webkit-animation-name: hideSubMenu;
  -webkit-animation-duration: .4s;
}
/******************************************************
                        sub MENU
******************************************************/
/* Mini menu */
.navbar-mini-menu {
  background-color: #08beb5;
  display: none;
}
.navbar-mini-menu .menu-select {
  color: #fff;
  padding: 1rem 1.5rem;
}
.navbar-mini-menu .menu-select .btn-select {
  background: url("https://imgur.com/VbcTojM.png") no-repeat;
  cursor: pointer;
  position: absolute;
  height: 30px;
  width: 30px;
  right: 10px;
  top: 10px;
}
.navbar-mini-menu .mini-menu-options {
  display: block;
}
.navbar-mini-menu .mini-menu-options li {
  display: block;
}
.navbar-mini-menu .mini-menu-options li .submenu {
  display: none;
}
.navbar-mini-menu .mini-menu-options li:focus {
  outline: 0;
}
.navbar-mini-menu .mini-menu-options li:focus > .submenu {
  display: block;
  -webkit-animation-name: showSubMenu;
  -webkit-animation-duration: .4s;
}
.navbar-mini-menu .mini-menu-options li a {
  display: block;
  padding: 1rem 1.5rem;
}
@-webkit-keyframes showSubMenu {
    0% {
      transform: scale(0,0);
    }
  100% {
    transform: scale(1,1);
  }
}
@-webkit-keyframes hideSubMenu {
  0% {
    transform: scale(1,1);
  }
  100% {
    transform: scale(0,0);
  }
}
@media screen and (max-width: 750px) {
  .navbar-menu {
    margin: 0;
  }
  .navbar-menu .menu {
    display: none;
  }
  .navbar-mini-menu {
    display: block;
  }
  .navbar-mini-menu .mini-menu-options {
    display: none;
  }
}
    </style>

Download Premium Plugins & Templates from Template Cafe

Step 3 – Add JavaScript

We use some external JavaScript link to this code. No need to worry about this, copy and paste below code between <head></head> tag.

<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" >
</head>

And also copy and paste below JavaScript code between <script></script> tag.

<script>
$(document).on("ready",function() {

  var menuState = 0;

    $(".btn-select").on("click",function() {
      if(menuState === 0) {
        $(".mini-menu-options").slideDown("slow");
        menuState = 1;
      } else {
        $(".mini-menu-options").slideUp("slow");
        menuState = 0;
      }
    });

  $(".mini-menu-options li").on("click", function() {
    var numHijos = $(this).children().length;
    if(numHijos < 2) {

      $(".mini-menu-options").hide("fast");

      var texto = $(this).text();

      $(".menu-select .menu-actual").text(texto);
    }
    menuState = 0; 
  });
});
</script>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

How to create a responsive navigation bar

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button