Side Revealing Navigation In Plain HTML/CSS

Category: Menu & Navigation | July 4, 2017
Author:tonkec
Views Total:1,118 views
Official Page:Go to website
Last Update:July 4, 2017
License:MIT

Preview:

Side Revealing Navigation In Plain HTML/CSS

Description:

A pure HTML/CSS approach to creating a hamburger menu toggle that reveals a side off-canvas drawer navigation when clicked.

How to use it:

<aside>
  <ul class="asideList">
    <li><a href="#" class="asideAnchor">Home</a></li>
    <li><a href="#" class="asideAnchor">Contact</a></li>
    <li><a href="#" class="asideAnchor">About</a></li>
    <li><a href="#" class="asideAnchor">Blog</a></li>
  </ul>
</aside>

Insert the main content and the hamburger menu toggle into the html document.

<section>
  <input type="checkbox" id="myInput">
  <label for="myInput">
    <span class="bar top"></span>
    <span class="bar middle"></span>
    <span class="bar bottom"></span>
  </label>
  <div class="content">
    Main Content Here
  </div>
</section>

Style the side navigation.

aside {
  background-color: #0799d3;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 20%;
  z-index: 1;
}
.asideList {
  list-style: none;
  padding: 0;
  margin: 0;
  margin-top: 100px;
  text-align: center;
  border-top: 2px solid rgba(255, 255, 255, .7);
}
.asideAnchor {
  border-bottom: 2px solid rgba(255, 255, 255, .7);
  padding: 20px 0;
  display: block;
  color: #fff;
  text-transform: uppercase;
  text-decoration: none;
  font-size: 20px;
  font-weight: 500;
  position: relative;
  transition: color .3s .15s ease-in;
}
.asideAnchor::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  background-color: #fff;
  width: 0;
  transition: width .3s ease-in;
  z-index: -1;
}
.asideAnchor:hover {
  color: #0799d3;
}
.asideAnchor:hover::after {
  width: 100%;
}

Style and activate the hamburger menu toggle.

label {
  display: inline-block;
  padding: 7px 10px;
  background-color: transparent;
  cursor: pointer;
  margin: 10px;
  z-index: 3;
  position: fixed;
}
.bar {
  display: block;
  background-color: #0799d3;
  width: 30px;
  height: 3px;
  border-radius: 5px;
  margin: 5px auto;
  transition: background-color .5s ease-in, transform .5s ease-in, width .5s ease-in;
}

input[type="checkbox"] {
  display: none;
}
input[type="checkbox"]:checked ~ .content {
  transform: translateX(20%);
}
input[type="checkbox"]:checked ~ label .bar {
  background-color: #fff;
}
input[type="checkbox"]:checked ~ label .top {
  -webkit-transform: translateY(0px) rotateZ(45deg);
  -moz-transform: translateY(0px) rotateZ(45deg);
  -ms-transform: translateY(0px) rotateZ(45deg);
  -o-transform: translateY(0px) rotateZ(45deg);
  transform: translateY(0px) rotateZ(45deg);
}
input[type="checkbox"]:checked ~ label .bottom {
  -webkit-transform: translateY(-15px) rotateZ(-45deg);
  -moz-transform: translateY(-15px) rotateZ(-45deg);
  -ms-transform: translateY(-15px) rotateZ(-45deg);
  -o-transform: translateY(-15px) rotateZ(-45deg);
  transform: translateY(-15px) rotateZ(-45deg);
}
input[type="checkbox"]:checked ~ label .middle {
  width: 0;
}

The basic styles for the main content.

main {
  height: 100%;
  width: 100%;
}
section {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #fff;
  overflow: hidden;
}
.content {
  top: 0;
  bottom: 0;
  position: absolute;
  right: 0;
  left: 0;
  background-color: #fff;
  z-index: 2;
  transition: transform .5s ease-in-out;
}

 

You Might Be Interested In:


Leave a Reply