Answers for "make navbar sticky"

CSS
7

stick menu bar in css

.navigation {
   /* fixed keyword is fine too */
   position: sticky;
   top: 0;
   z-index: 100;
   /* z-index works pretty much like a layer:
   the higher the z-index value, the greater
   it will allow the navigation tag to stay on top
   of other tags */
}
Posted by: Guest on July-30-2020
2

sticky operations in javascript

var siteHeader = document.getElementById('siteHeader'),
    siteNav = document.getElementById('siteNav');

    window.onscroll = function() {
        if ( siteNav.offsetTop < document.documentElement.scrollTop + 26 || siteNav.offsetTop < document.body.scrollTop + 26) {
            siteHeader.setAttribute("class","sticky");
        }
        else {
            siteHeader.setAttribute("class","");
        }
    }
Posted by: Guest on December-01-2020
1

css sticky navigatiojn

nav {
	position:sticky;
	top:0;
}

/*Top can be replaced with bottom, left, or right 
	depending on what you want :) */
Posted by: Guest on November-05-2020
4

sticky navbar

<!-- The simplest solution: NO JAVASCRIPT, ONLY 3 LINES OF CODE.-->
<!-- Please vote if you find this useful -->

            <nav style="position: fixed;top; 0px;left: 0px;right: 0px;background-color: #ccc;padding: 20px;color: #fff!important;">
                <a href="#">MY COMPANY</a>
            </nav>
Posted by: Guest on July-26-2021

Browse Popular Code Answers by Language