Sliding Push Navigation Menu In Pure CSS

Category: CSS & CSS3 , Menu & Navigation | June 25, 2017
Author: james_zedd
Views Total: 4,005
Official Page: Go to website
Last Update: June 25, 2017
License: MIT

Preview:

Sliding Push Navigation Menu In Pure CSS

Description:

An off-canvas drawer navigation that slides out and pushes the main content to the right when opened, completely written in pure HTML and CSS.

How to use it:

Create a toggle icon for the drawer navigation. In this case, we’re going to use Font Awesome Iconic Font for the icon.

<input type="checkbox" id="menu-toggle" />
<label for="menu-toggle" class="menu-icon"><i class="fa fa-bars"></i></label>

Create the main content together with a drawer menu on the webpage.

<div class="content-container">
  Main Content Here
</div>

<div class="slideout-sidebar">
  <ul>
    <li>Home</li>
    <li>About</li>
    <li>Blog</li>
    <li>Contact</li>
  </ul>
</div>

Style the main content & drawer menu.

/* -- Slideout Sidebar -- */

.slideout-sidebar {
  position: fixed;
  top: 0;
  left: -190px;
  z-index: 0;
  width: 150px;
  height: 100%;
  padding: 20px;
  background-color: #212121;
  transition: all 300ms ease-in-out;
}

/* -- Slideout Sidebar -- */

.slideout-sidebar {
  position: fixed;
  top: 0;
  left: -190px;
  z-index: 0;
  width: 150px;
  height: 100%;
  padding: 20px;
  background-color: #212121;
  transition: all 300ms ease-in-out;
}

.slideout-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.slideout-sidebar ul li {
  cursor: pointer;
  padding: 18px 0;
  border-bottom: 1px solid rgba(244,244,244,0.4);
  color: rgba(244,244,244,0.7);
}

.slideout-sidebar ul li:last-child {
  border-bottom: 0;
}

.slideout-sidebar ul li:hover {
  color: rgba(244,244,244,1);
}

Enable the menu toggle icon.

#menu-toggle {
  display: none;
}

.menu-icon {
  position: absolute;
  top: 18px;
  left: 30px;
  font-size: 24px;
  z-index: 1;
  transition: all 300ms ease-in-out;
}


/*-- The Magic --*/
#menu-toggle:checked ~ .slideout-sidebar {
  left: 0px;
}

#menu-toggle:checked + .menu-icon {
  left: 210px;
}

#menu-toggle:checked ~ .content-container {
  padding-left: 190px;
}

The CSS to make the drawer navigation perform well on small screen.

@media (max-width: 991px) {
  
  .content-container {
    max-width: 480px;
  }
  
}

@media (max-width: 767px) {
  
  .content-container {
    max-width: 100%;
    margin: 30px auto 0;
  }
  
  #menu-toggle:checked ~ .content-container {
    padding-left: 0;
  }
  
  .slideout-sidebar ul {
    text-align: center;
    max-width: 200px;
    margin: 30px auto 0;
  }
  
  .menu-icon {
    left: 20px
  }
  
  #menu-toggle:checked ~ .slideout-sidebar {
    width: 100%;
  }
  
  #menu-toggle:checked + .menu-icon {
    left: 87%;
    color: #fafafa;
  }
  
  @media screen  
    and (max-width: 736px) 
    and (orientation: landscape) {
      
      .slideout-sidebar {
        padding: 0;
      }
      
      .slideout-sidebar ul {
        max-width: 100%;
        margin: 60px auto 0;
      }
      
      .slideout-sidebar ul li {
        display: inline-block;
        border-bottom: 0;
        width: 72px;
        padding: 18px 24px;
        margin: 0 6px 12px;
        color: #ffffff;
        background-color: #777;
      }

  }
  
}

You Might Be Interested In:


Leave a Reply