Blogger Ever

Create a full screen navigation using CSS and Javascript

Working on flat and material designs recently, I found that navigation are getting older since, simple bar doesn't looks in-fashion. Why don't we create a full screen navigation to tackle the design problem.

Full screen navigation worth coding not just due to design sense, but the content and links get more space on screen. Further there is no need to code so much Javascript, just for the purpose of toggling classes I am using Javascript. Here is the demo:
See the Pen Full Screen Nav by Mohammad Hamza Dhamiya (@hamzadhamiya) on CodePen.

The journey starts with markup or HTML. First, we need is the navicon, a button to trigger the navigation.Then a parent navigation tag (<nav>) but make sure that <nav> tag doesn't have any parent with position relative, otherwise positioning will be effected.
<header><span class='navicon'>&#xf0c9;</span>
  <h1>Full Screen Nav</h1></header>
  <span class='closeB'>&#xf00d;</span>
    <li><a href='#'><span>&#xf015;</span> Home</a></li>
    <li><a href='#'><span>&#xf09e;</span> Blog</a></li>
    <li><a href='#'><span>&#xf0e0;</span> Contact</a></li>
    <li><a href='#'><span>&#xf06a;</span> About</a></li>
    <li><a href='#'><span>&#xf004;</span> Donate</a></li>
  <div class='info'>
      <li><span>&#xf232;</span> Whatsapp<br>+12-324-5678</li>
      <li><span>&#xf199;</span> Email<br>[email protected]</li>
      <li><span>&#xf124;</span> Address<br>Google Inc HQ, Mountain View, California, US</li>
Next is we need is to make sure that body tag doesn't show scroll bar when the navigation is active. We need to toggle active class to several elements, for functional as well as for design reasons. FOr that just add several lines of JS.
var navicon=document.querySelector('.navicon'),
function toggleStuff(){
Next is to hide the navigation and then display it when active class is added. That old technique using visibility and opacity properties. Use transition to make a little fade in effect.
nav {
  position: fixed;
  overflow-y: auto;
  left: 0;
  top: -20px;
  width: 100%;
  height: 100%;
  background: #2c3e50;
  -webkit-transition: all .3s ease-in-out;
  -moz-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
} {
To hide the scroll bar while navigation is open, just add overflow-y:hidden to body tag with active class. You can see the whole CSS in pen.

This was just a demo, many possibilities are around.

2013-2016 Copyright Blogger E\ver . Coded, managed and founded by Mohammad Hamza (@hamzadhamiya) . Hosted on Blogger and fonts used are Raleway and Open Sans.