CSS Navigation Bar With Sliding

Introduction

This article shows how to create a unique toggle menu with a Menu slide. This toggle menu is made up of icons only and when the user hovers over them then the title of that icon will be shown. The icon will slide from left to right side, when the user clicks on the toggle button. 
 
This menu is designed in HTML5/CSS. We used a HTML5 input checkbox type attribute to do so and used advanced CSS3 selectors to add functionality to this icon menu. For this article I am using font-awesome.min.css that you can download.
 
Let's start. First of all I am creating a HTML document. 
  1. <!doctype html>  
  2. <html lang="en">  
  3. <head>  
  4.  <meta charset="UTF-8">  
  5.  <title>Navigation Bar</title>  
  6.  <meta name="viewport" content="width=device-width, initial-scale=1.0">   
  7.  <link rel="stylesheet" href="style.css">  
  8.  <link rel="stylesheet" href="css/font-awesome.min.css">  
  9. </head>  
  10. <body>  
  11.  <input type="checkbox" id="navbutton" name="navbutton">   
  12.  <nav class="sm-menu">  
  13.  <label for="navbutton" class="nav-trigger"><i class="fa fa-bars"></i></label>  
  14.  <ul class="na-menu">  
  15.  <li><a href="http://www.c-sharpcorner.com/authors/75a48f/sourabh-somani.aspx"><i class="fa fa-home"></i><span>Home</span></a></li>  
  16.  <li><a href="http://www.sourabhsomani.com"><i class="fa fa-map-marker"></i><span>contact me</span></a></li>  
  17.  <li><a href="https://www.facebook.com/HackerSourabh"><i class="fa fa-facebook"></i><span>Facebook</span></a></li>  
  18.  <li><a href="https://twitter.com/sourabh_somani"><i class="fa fa-twitter"></i><span>Twitter</span></a></li>  
  19.  <li><a href="http://www.c-sharpcorner.com/authors/75a48f/sourabh-somani.aspx"><i class="fa fa-thumbs-up"></i><span>Like Me</span></a></li>  
  20.  </ul>  
  21.  </nav>  
  22. </body>  
  23. </html>  
From the preceding HTML code we will get the following output:
 
Now add the following CSS rules to set the styles to the navigation bar.
  1. body, ul, li{  
  2.  padding0;  
  3.  margin0;  
  4. }  
  5. /*ADDING STYLE TO MAIN WRAPPER*/  
  6. nav.sm-menu{  
  7.  background: rgba(0000.75);  
  8.  color#fff;  
  9.  width100%;  
  10.  positionfixed;  
  11.  z-index9999;  
  12.  top: 0;  
  13.  left: 0;  
  14.  font-familyarial;  
  15. }  
  16. /*ADDING STYLE TO TRIGGER BUTTON*/  
  17. .nav-trigger{  
  18.  font-size36px;  
  19.  padding5px 10px;  
  20.  floatleft;  
  21.  background#0FC;  
  22.  cursorpointer;  
  23. }  
  24. .nav-trigger:hover{  
  25.  background#0FF;  
  26. }  
  27. .nav-trigger i{  
  28.  padding5px;  
  29.  color#585858;  
  30.  -webkit-transition: -webkit-transform 0.5s ease-in-out;  
  31.  -moz-transition: -moz-transform 0.5s ease-in-out;  
  32.  -ms-transition: -ms-transform 0.5s ease-in-out;  
  33.  -o-transition: -o-transform 0.5s ease-in-out;  
  34.  transition: -webkit-transform 0.5s ease-in-out;  
  35. }  
  36. input[type=checkbox]:checked + nav.sm-menu .nav-trigger i{  
  37.  -webkit-transform: rotate(90deg);  
  38.  -moz-transform: rotate(90deg);  
  39.  -ms-transform: rotate(90deg);  
  40.  -o-transform: rotate(90deg);  
  41.  transform: rotate(90deg);   
  42. }  
  43. /*STYLE TO LIST*/  
  44. nav.sm-menu ul{  
  45.  display: inline-block;  
  46.  positionrelative;  
  47.  left: -100%;  
  48.  -webkit-transition: left 0.5s ease-in-out;  
  49.  -moz-transition: left 0.5s ease-in-out;  
  50.  -ms-transition: left 0.5s ease-in-out;  
  51.  -o-transition: left 0.5s ease-in-out;  
  52.  transition: left 0.5s ease-in-out;  
  53. }  
  54. /*STYLE TO LIST ITEMS*/  
  55. nav.sm-menu li{  
  56.  displayblock;  
  57.  floatleft;  
  58. }  
  59. /*STYLE TO LINKS*/  
  60. nav.sm-menu li a{  
  61.  color#cccccc;  
  62.  height50px;  
  63.  font-size30px;  
  64.  margin-top1px;  
  65.  line-height60px;  
  66.  text-aligncenter;  
  67.  displayblock;  
  68.  padding0 20px;  
  69.  text-decorationnone;  
  70. }  
  71. nav.sm-menu li a:hover{  
  72.  color#fff;  
  73. }  
  74. nav.sm-menu li a i{  
  75.  font-size36px;  
  76. }  
  77. nav.sm-menu li a span{  
  78.  positionabsolute;  
  79.  left: 100%;  
  80.  top: 0;  
  81.  width:100%;  
  82.  padding0 20px;  
  83.  height100%;  
  84.  font-size24px;  
  85.  text-alignleft;  
  86.  line-height55px;  
  87.  text-transformcapitalize;  
  88.  opacity: 0;  
  89.  visibilityhidden;  
  90.  -webkit-transition: opacity 0.2s ease, visibility 0.2s ease;  
  91.  -moz-transition: opacity 0.2s ease, visibility 0.2s ease;  
  92.  -ms-transition: opacity 0.2s ease, visibility 0.2s ease;  
  93.  -o-transition: opacity 0.2s ease, visibility 0.2s ease;  
  94.  transition: opacity 0.2s ease, visibility 0.2s ease;   
  95. }  
  96. nav.sm-menu li a:hover span{  
  97.  opacity: 1;  
  98.  visibilityvisible;  
  99. }  
  100. /*SENDING INPUT CHECKBOX OUT OF BROWESER WINDOW*/  
  101. input[type=checkbox]{  
  102.  positionabsolute;  
  103.  top: -99px;  
  104. }  
  105.   
  106. /*SENDS THE MENU TO -100% LEFT*/  
  107. nav.sm-menu ul{  
  108.  left: -100%;  
  109. }  
  110. /*BRINGS BACK THE ICONS MENU WHEN INPOUT IS CHECKED*/  
  111. input[type=checkbox]:checked + nav.sm-menu ul {  
  112.  left: 0;  
  113. }  
Output
 

Up Next
    Ebook Download
    View all
    Learn
    View all
    sourabhsomani.com