CSS Only Responsive Hamburger Navigation

Category: Javascript , Menu & Navigation | October 11, 2017
Author: KJthealien
Views Total: 120
Official Page: Go to website
Last Update: October 11, 2017
License:

Preview:

CSS Only Responsive Hamburger Navigation

Description:

Yet another responsive, mobile-friendly hamburger navigation menu for your cross-platform web pages. Implemented with pure HTML and CSS/CSS3.

How to use it:

Create a header navigation for your website as follows:

<header class="header navbar-fixed-top">
  
  <!-- Navbar -->
  <nav class="navbar" role="navigation">
      <div class="container">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="menu-container js_nav-item">
          </div>
          <!-- HAMBURGUER MENU ICON -->
          <input type="checkbox" name="toggle" id="toggle"/>
          <label for="navbar-toggle"></label>
          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="menu-mobile">
              <div class="collapse navbar-collapse nav-collapse ">
                  <div class="menu-container">
                      <ul class="nav navbar-nav container-right ">
                          <li class="js_nav-item nav-item"><a class="nav-item-child" href="#">Home</a></li>
                          <li class="js_nav-item nav-item"><a class="nav-item-child" href="#">About Us</a></li>
                          <li class="js_nav-item nav-item"><a class="nav-item-child" href="#">Our Partners</a></li>
                          <li class="js_nav-item nav-item"><a class="nav-item-child" href="#">Contact</a></li>
                      </ul>
                  </div>
              </div>
        </div>
      </div>
  </nav>
  
</header>

The main CSS styles for the header navigation.

/* Header fixed and background colors */

.header {
  position: fixed;
  top: 0px;
  max-height: 100px;
  z-index: 999;
  width: 100%;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
  opacity: 1;
}

/* UL element Navigation Main Menu */

.navbar-collapse {
  max-height: 100%;
  padding-left: 0;
  padding-right: 0;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar {
  margin-bottom: 0;
  background-color: #003366;
  border-radius: 0px;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-nav {
  padding-left: 0;
  margin-bottom: 0;
  list-style: none
}

.header .navbar {
  margin-bottom: 0;
  background-color: #1a1a44;
  border-bottom: 3px #ae952e solid;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1);
  position: relative;
  min-height: 100px;
  margin-bottom: 20px;
}

.navbar-nav { padding-right: 30px; }

/* Menu LI items and children */

.navbar-nav {
  list-style: none;
  margin-top: 55px;
  padding-right: 20px;
}

li.nav-item {
  position: relative;
  font-size: 1em;
  float: left;
  height: 50px;
  padding-left: 30px; /* space between menu items */
}

a.nav-item-child {
  font-size: 1em;
  font-family: 'Oswald', sans-serif !important;
  color: #fff;
  line-height: 25px;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.navbar-nav>li.nav-item>a:hover {
  margin-bottom: 10px;
  border-bottom: 2px solid #ae952e;
  padding-bottom: 3px;
  color: #ccc;
}

header .nav-item-child:focus, .header .nav-item-child:hover { background: inherit }

/* MAX-WIDTH 767px */
@media (max-width:767px) {

.header .menu-container {
  padding-left: 15px;
  padding-right: 15px;
  margin-left: 0;
  margin-right: 0
}

.header .navbar>.container, .header .navbar>.container>.nav-collapse {
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0
}

.header .navbar>.container { width: auto }
}

The CSS styles for the menu toggle.

.header .nav-item-hover:after, .link:after, .work .work-overlay:before { content: " " }

.header .navbar-toggle {
  width: 45px;
  height: 35px;
  border: none;
  margin: 35px 0;
  position: relative;
  float: right;
  padding: 9px 10px;
  margin-top: 31px;
  margin-right: 35px;
  margin-bottom: 8px;
  background-color: transparent;
  background-image: none;
  border: 1px solid transparent;
  border-radius: 4px;
}

.header .navbar-toggle .toggle-icon {
  position: relative;
  width: 21px;
  height: 1px;
  display: inline-block;
  background: #fff;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-toggle .toggle-icon:after, .header .navbar-toggle .toggle-icon:before {
  position: absolute;
  left: 0;
  background: #fff;
  content: " "
}

.header .navbar-toggle .toggle-icon:before {
  width: 10px;
  height: 1px;
  bottom: 10px;
  -webkit-transform: rotate(0);
  -moz-transform: rotate(0);
  transform: rotate(0);
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-toggle .toggle-icon:after {
  width: 16px;
  height: 1px;
  top: -5px;
  -webkit-transform: rotate(0);
  -moz-transform: rotate(0);
  transform: rotate(0);
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-toggle:hover .toggle-icon {
  background: #ae952e;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-toggle:hover .toggle-icon:after, .header .navbar-toggle:hover .toggle-icon:before {
  width: 21px;
  height: 1px;
  background: #ae952e;
  transition-duration: .3s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .header .logo-img-main, .header .nav-item.active .nav-item-hover:after, .header .nav-item:hover .nav-item-hover:after {
  transition-duration: .4s;
  transition-property: all;
  transition-timing-function: cubic-bezier(.7, 1, .7, 1)
}

.header .navbar-toggle:hover .toggle-icon.is-clicked { background: rgba(81,87,105,0) }

/* MIN-WIDTH 768px */
@media (min-width: 768px) {

.navbar-toggle { display: none; }
}

The core CSS for the responsive menu.

/* MAX-WIDTH 991px */
@media (max-width:991px) {

.header .navbar-nav {
  margin: 0;
  float: none
}

.header .navbar-nav .nav-item { float: none }

.header .menu-container:after, .header .menu-container:before {
  content: " ";
  display: table
}

.header .menu-container:after { clear: both }

.header .logo .logo-img-main { display: none }

.header .logo .logo-img-active { display: inline-block }

.header .nav-item-child {
  line-height: 1.4;
  padding: 12px 12px 12px 15px
}

.header .nav-item-hover:after {
  position: absolute;
  top: 19px
}

/*======= TOGGLE MENU ======*/

#toggle, #toggle + label { display: inherit; }

#toggle {
  width: 45px;
  height: 40px;
  opacity: 0;
  border: none;
  margin: 35px 0;
  position: absolute;
  top: 0px;
  right: 0px;
  z-index: 1000;
  float: right;
  padding: 9px 10px;
  margin-top: 31px;
  margin-right: 35px;
  margin-bottom: 8px;
  background-color: transparent;
  background-image: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}

.menu-mobile {
  padding-top: 90px;
  text-align: center;
  background: #1a1a44;
  color: #FFF;
  width: 100%;
  height: 0px;
  overflow: hidden;
  transition: height 300ms cubic-bezier(0.17, 0.04, 0.03, 0.94);
}

#toggle:checked ~ .menu-mobile { height: 300px; }

#toggle + label {
  position: absolute;
  top: 27px;
  right: 50px;
  border: none;
  color: #ffffff;
  background-color: transparent;
  background-image: none;
  border: 1px solid transparent;
  border-radius: 4px;
}

#toggle + label:after {
  content: '\2630';
  font-size: 1.7em;
}

#toggle:hover + label { color: #ae952e; }

#toggle:checked ~ .message { height: 150px; }

#toggle:checked + label:after {
  content: '\2573';
  font-size: 1.4em;
}
}

/* MIN-WIDTH 992px */
@media (min-width:992px) {

.header .navbar-nav-right { float: right }

}