1.navigation {
2 /* fixed keyword is fine too */
3 position: sticky;
4 top: 0;
5 z-index: 100;
6 /* z-index works pretty much like a layer:
7 the higher the z-index value, the greater
8 it will allow the navigation tag to stay on top
9 of other tags */
10}
1var siteHeader = document.getElementById('siteHeader'),
2 siteNav = document.getElementById('siteNav');
3
4 window.onscroll = function() {
5 if ( siteNav.offsetTop < document.documentElement.scrollTop + 26 || siteNav.offsetTop < document.body.scrollTop + 26) {
6 siteHeader.setAttribute("class","sticky");
7 }
8 else {
9 siteHeader.setAttribute("class","");
10 }
11 }
12
1nav {
2 position:sticky;
3 top:0;
4}
5
6/*Top can be replaced with bottom, left, or right
7 depending on what you want :) */
1<!-- The simplest solution: NO JAVASCRIPT, ONLY 3 LINES OF CODE.-->
2<!-- Please vote if you find this useful -->
3
4 <nav style="position: fixed;top; 0px;left: 0px;right: 0px;background-color: #ccc;padding: 20px;color: #fff!important;">
5 <a href="#">MY COMPANY</a>
6 </nav>