Professional Documents
Culture Documents
Certainly
Certainly
Below is an example of a simple HTML, CSS, and JavaScript code snippet for creating a sticky
header on a website:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
header {
background-color: #333;
color: white;
padding: 15px;
text-align: center;
position: fixed;
width: 100%;
top: 0;
section {
padding: 50px;
}
</style>
</head>
<body>
<header id="header">
<h1>Sticky Header</h1>
</header>
<section>
<h2>Main Content</h2>
</section>
<script>
window.onscroll = function() {
header.style.top = "0";
} else {
header.style.top = "-50px";
};
</script>
</body>
</html>
```
This code creates a basic webpage with a sticky header. The header becomes visible when you scroll
down and hides when you scroll up. You can customize the styles and behavior according to your
specific needs.