Certainly! Here’s an example of how you can create a sticky header for a website using HTML, CSS, and JavaScript:
HTML:
html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="script.js" defer></script>
<title>Sticky Header Example</title>
</head>
<body>
<header class="sticky-header">
<h1>My Sticky Header</h1>
</header>
<div class="content">
<!-- Your website content goes here -->
</div>
</body>
</html>
CSS (styles.css):
css
/* Styles for the sticky header */
.sticky-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #333;
color: #fff;
padding: 10px 0;
text-align: center;
z-index: 100;
}
/* Styles for the page content to prevent it from being hidden behind the header */.content {
margin-top: 100px; /* Adjust this value to match the header’s height */
}
JavaScript (script.js):
javascript
// JavaScript to add a "sticky"
lojyg
Reviews
There are no reviews yet.