Creating a Fixed Menu Control

Let's create a menu box in such a way that it will remain at a fixed position and will be available even after scrolling the page.
 
In order to do so,we will make sure that the css of the particular div is defined to make the position as fixed. Also you will find some other css which is only to make the menu worth looking.
 
The style would be as below:
  1. <style>  

  2. div.floating-menu  
  3. {   position:fixed;  
  4. background:#ff6a00;  
  5. border:1px solid #ff6a00;  
  6. width:150px;  
  7. z-index:100;  }  
  8.    
  9. div.floating-menu a, div.floating-menu h3  
  10. {  display:block;  
  11. margin:0 0.5em; }  

  12. </style>  
And the div that would use the class be as:
  1. <div class="floating-menu">  
  2.   
  3.                           <a href="#">Link1</a>  
  4.                           <a href="#">Link2</a>  
  5.                           <a href="#">Link3</a>  
  6.                           <a href="#">Link4</a>  
  7.                           <a href="#">Link5</a>  
  8.  </div>  
After doing that the output would be a panel  that would remain fixed irrespective of the scroll.

It's the "position:fixed;" condition that makes the panel fixed.
 
I have tested the same on the below browsers and it's working fine:
  • Chrome: Version 43.0.2357.130 m
  • IE: IE10  
It might not work in the old browsers so we would have to check it again. 
 
Thanks for reading. 
Ebook Download
View all
Learn
View all