Create Responsive navigation menu bar

Create Responsive navigation menu bar

Today in this blog you’ll learn how to create a Fully Responsive Navigation Menu Bar using only HTML CSS & JavaScript. In the earlier blog, I have shared how to create a Responsive Sidebar Menu using HTML CSS & JavaScript and now it’s time to create a navigation bar in HTML.

To create this responsive navigation bar. First, you need to create two Files one HTML File and another one is CSS File.

HTML CODE:

<nav>
  <label class="toggle">
    <i class="fas fa-bars"></i>
  </label>
  <ul>
    <li><a class="active" href='#'>Home</a></li>
    <li><a href='#'>Download</a></li>
    <li><a href='#'>Social</a></li>
    <li><a href='#'>Features</a></li>
    <li><a href='#'>Entertainment</a></li>
    <li><a href='#'>Travelling</a></li>
    <li><a href='#'>Contact</a></li>
  </ul>
  <div class="socialtop">
    <div class='top-social'>
      <a href='#'><i class='fab fa-facebook-f'></i></a>
      <a href='#'><i class='fab fa-twitter'></i></a>
      <a href='#'><i class='fab fa-instagram'></i></a>
      <a href='#'><i class='fab fa-pinterest'></i></a>
      <a href="#"><i class='fab fa-youtube'></i></a>
    </div>
  </div>
</nav>

CSS CODE:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: #f1f1f1;
}

.toggle {
  font-size: 30px;
  color: white;
  float: left;
  line-height: 45px;
  margin-left: 5%;
  cursor: pointer;
  display: none;
}

nav {
  background: #fff;
  height: 45px;
  width: 100%;
  box-shadow: 0 0 10px 0 rgba(0 0 0 0.05);
}

ul {
  float: left;
  margin-left: 5%;
}

.socialtop {
  float: right;
  margin-right: 5%;
}

ul li {
  margin: 0;
  padding: 0;
  position: relative;
  display: inline-block;
  font-size: 16px;
}

ul a {
  font-weight: 400;
  padding: 15px;
  line-height: 45px;
  color: #000;
  font-weight: 700;
  font-family: sans-serif;
  font-size: .8rem;
  text-transform: uppercase;
  text-decoration: none;
}

ul li a.active{
  background: #ddd;
}

ul li:hover {
  background: #000000;
  color: #fff;
}

ul li a:hover {
  color: #fff;
}

.top-social a {
  padding: 13px;
  color: #fff;
}

.top-social {
  padding: 14px 15px;
}

.top-social a{
  color: #000011;
}

.top-social a:hover {
  color: #000;
}

@media screen and (max-width: 991px) {
  .toggle {
    display: block;
    color: #000;
  }

  ul {
    z-index: -1;
    margin-top: -15px;
    position: fixed;
    top: 60px;
    right: 0;
    left: 0;
    width: 200px;
    background: #222222;
    display: inline-block;
    transition: left .4s;
    margin-left: 0;
    height: 100%
  }

  ul.show {
    left:-100%;
  }

  ul li {
    top: 0;
    width: 100%;
    float: left;
    text-align: center;
  }
  
  ul li a{
    color: #fff;
  }
  ul li a.active{
    background: transparent;
    color: #ccc;
  }
}

@media screen and (max-width:500px) {
  ul {
    width: 100%;
    left: 0;
  }

}

JAVASCTIPT CODE:

const navbarToggler = document.querySelector('.toggle');
const navbarCollapse = document.querySelector('ul');

navbarToggler.addEventListener('click', () => {
    navbarToggler.classList.toggle('change');
    navbarCollapse.classList.toggle('show');
});

That’s all, now you’ve successfully created a Responsive Navigation Menu Bar using HTML CSS & JavaScript.

Preview

See the Pen responsive menu by Rashedul Hasan (@rhsuman) on CodePen.

RH Suman
RH Suman
Articles: 64

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply