nav {
position: sticky; top: 0;
}
<!-- https://www.w3schools.com/howto/howto_js_sticky_header.asp -->
<style>
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 102px;
}
</style>
<script>
window.onscroll = function() {myFunction()};
var desktopHeader = document.getElementById("yourHeader");
var stickyHeader = desktopHeader.offsetTop;
function myFunction()
{
if(window.pageYOffset > stickyHeader)
{
desktopHeader.classList.add("sticky");
}
else
{
desktopHeader.classList.remove("sticky");
}
}
</script>
Code Example |
---|
Css :: css responsive font size |
Css :: css photo circle |
Css :: centred div |
Css :: css smooooooth scroll |
Css :: table td remove unknown padding in td |
Css :: box-shadow |
Css :: css caret-color property |
Css :: scss watch command |
Css :: css border on part of side |
Css :: reduce image size css |
Css :: css animation stop at the end |
Css :: ovale css |
Css :: css last of type |
Css :: how to remove border of a specific side of td in css |
Css :: scss install |
Css :: sm size website |
Css :: css center vertically |
Css :: how to lighten a color in css |
Css :: border color transparent |
Css :: how to make the list in css with square |
Css :: make an image smaller css |
Css :: css first h element |
Css :: css blur |
Css :: border properties css |
Css :: css background rainbow |
Css :: checkbox border css |
Css :: css cursor loading |
Css :: increase font size zenity |
Css :: have background color and background image css |
Css :: tailwind @apply |