Gochi vay tiền online siêu nhanh bao vay toàn quốc chỉ cần CMND
Certainly! Below is a simple example of how you can create a sticky header using HTML, CSS, and JavaScript:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: center;
position: fixed;
width: 100%;
top: 0;
z-index: 1000;
}
section {
padding: 20px;
margin-top: 60px; /* Adjust this margin to prevent content from being hidden under the sticky header */
}
/* Add additional styling for your content if needed */
/* Optional: Add a smooth transition effect */
header {
transition: background-color 0.3s ease;
}
/* Optional: Change header style on scroll */
header.scrolled {
background-color: #555;
}
</style>
</head>
<body>
<header>
<h1>Sticky Header</h1>
</header>
<section>
<h2>Main Content Goes Here</h2>
<!-- Add more content as needed -->
</section>
<script>
// JavaScript to add a class when scrolling
window.addEventListener('scroll', function () {
const header = document.querySelector('header');
const scrollY = window.scrollY;
if (scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
</script>
</body>
</html>
```
In this example, the header will become sticky at the top of the page when you scroll down. You can customize the styling and adjust the JavaScript scroll threshold according to your needs.
4.8/5 (94 votes)
Có thể bạn quan tâm: