Sticky header

Developer
Size
2,716 Kb
Views
14,168

How do I make an sticky header?

What is a sticky header? How do you make a sticky header? This script and codes were developed by Milano_O on 11 December 2022, Sunday.

Sticky header Previews

Sticky header - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Sticky header</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { height: 1200px; margin: 0; padding: 0;
}
.my-header { position: fixed; line-height: 60px; top: 30px; width: 100%; background: indianred; -webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -ms-transition: all 0.4s ease-in-out; -o-transition: all 0.4s ease-in-out; transition: all 0.4s ease-in-out; border-bottom: 1px solid #e8e8e8;
}
.my-header .main-nav ul { float: right;
}
.my-header .main-nav ul li { float: left; padding: 0 20px 0 0;
}
.my-header .logo { float: left; padding: 0 20px;
}
.my-header.sticky-header { top: 0; padding: 10px 0; margin: 0 auto; height: 60px; background: #333; -webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -ms-transition: all 0.4s ease-in-out; transition: all 0.4s ease-in-out;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="my-header"> <nav class="main-nav"> <ul> <li>Link1</li> <li>Link2</li> <li>Link3</li> <li>Link4</li> </ul> </nav> <div class="logo">LOGO</div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Sticky header - Script Codes CSS Codes

body { height: 1200px; margin: 0; padding: 0;
}
.my-header { position: fixed; line-height: 60px; top: 30px; width: 100%; background: indianred; -webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -ms-transition: all 0.4s ease-in-out; -o-transition: all 0.4s ease-in-out; transition: all 0.4s ease-in-out; border-bottom: 1px solid #e8e8e8;
}
.my-header .main-nav ul { float: right;
}
.my-header .main-nav ul li { float: left; padding: 0 20px 0 0;
}
.my-header .logo { float: left; padding: 0 20px;
}
.my-header.sticky-header { top: 0; padding: 10px 0; margin: 0 auto; height: 60px; background: #333; -webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -ms-transition: all 0.4s ease-in-out; transition: all 0.4s ease-in-out;
}

Sticky header - Script Codes JS Codes

$(window).scroll(function() { if ($(this).scrollTop() > 1) { $('.my-header').addClass("sticky-header"); } else { $('.my-header').removeClass("sticky-header"); }
});
Sticky header - Script Codes
Sticky header - Script Codes
Home Page Home
Developer Milano_O
Username milanodituti
Uploaded December 11, 2022
Rating 3
Size 2,716 Kb
Views 14,168
Do you need developer help for Sticky header?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Milano_O (milanodituti) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!