Table of Contents

Animated Hamburger Menu Toggle

Animation to have the 3 line hamburger menu turn into an x


HTML

Replace the normal bootstrap hamburger menu in the navbar with the following

<button class="navbar-toggler collapsed" type="button" data-toggle="collapse"
         data-target="#mainMenu" aria-controls="navbarsExampleDefault" aria-expanded="false"
         aria-label="Toggle navigation"
>
    <span class="icon-bar top-bar"></span>
    <span class="icon-bar middle-bar"></span>
    <span class="icon-bar bottom-bar"></span>
</button>

CSS

And add the following CSS

.navbar-toggler {
  border: none !important;
}
.icon-bar {
  width: 22px;
  height: 2px;
  background-color: #B6B6B6;
  display: block;
  transition: all 0.2s;
  margin-top: 4px;
}
.navbar-toggler {
  border: none;
  background: transparent !important;
}
.navbar-toggler .top-bar {
  transform: rotate(45deg);
  transform-origin: 10% 10%;
}
.navbar-toggler .middle-bar {
  opacity: 0;
}
.navbar-toggler .bottom-bar {
  transform: rotate(-45deg);
  transform-origin: 10% 90%;
}
.navbar-toggler.collapsed .top-bar {
  transform: rotate(0);
}
.navbar-toggler.collapsed .middle-bar {
  opacity: 1;
}
.navbar-toggler.collapsed .bottom-bar {
  transform: rotate(0);
}

Example