Creating An App Style Drawer Menu With Pure CSS/CSS3

Category: CSS & CSS3 , Menu & Navigation | December 23, 2014
Author:exull
Views Total:8,977 views
Official Page:Go to website
Last Update:December 23, 2014
License:MIT

Preview:

Creating An App Style Drawer Menu With Pure CSS/CSS3

Description:

A cool mobile App style navigation that reveals a familiar off-canvas menu and pushes the main content to the right. Written with pure CSS/CSS3.

How to use it:

Create an input field with a label for the toggle button.

<input type="checkbox" id="drawer-toggle">
<label for="drawer-toggle" id="drawer-toggle-label"></label>

Create a drawer menu from <nav> list.

<nav id="drawer">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>

The required CSS for the toggle button.

#drawer-toggle-label:before {
  content: "";
  display: block;
  position: absolute;
  height: 2px;
  width: 24px;
  background: #fff;
  left: 13px;
  top: 18px;
  box-shadow: 0 6px 0 #fff, 0 12px 0 #fff;
}
#drawer-toggle-label {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  height: 50px;
  width: 50px;
  z-index: 1;
  background: transparent;
}
#drawer-toggle { display: none; }
#drawer-toggle:checked ~ #drawer-toggle-label,
#drawer-toggle:checked ~ header { left: calc(100% - 50px); }
#drawer-toggle:checked ~ #drawer {
  width: calc(100% - 50px);
  left: 0;
}
#drawer-toggle:checked ~ section.content-wrapper { margin-left: 250px; }
 
@media screen and (min-width: 380px) {
#drawer-toggle:checked ~ #drawer-toggle-label,
#drawer-toggle:checked ~ header { left: 300px; }
#drawer-toggle:checked ~ #drawer {
  width: 300px;
  left: 0;
}
}

The CSS to style the draw menu.

#drawer {
  position: fixed;
  top: 0;
  padding-top: 50px;
  height: 100%;
  width: 250px;
  background: #2f2f2f;
  overflow-x: hidden;
  overflow-y: auto;
  left: -250px;
 background:
}
#drawer ul {
  list-style: none;
  padding: 0;
}
#drawer li a {
  display: block;
  color: #fff;
  text-decoration: none;
  text-align: center;
}
#drawer li {
  margin: 0;
  width: 100%;
  padding: 10px 0
}
#drawer { padding-top: 10px; }

You Might Be Interested In:


Leave a Reply