Untitled

 avatar
unknown
plain_text
2 years ago
922 B
5
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sticky Header Example</title>
  <style>
    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }

    header {
      background-color: #333;
      color: #fff;
      padding: 10px;
      text-align: center;
      position: fixed;
      width: 100%;
      top: 0;
      z-index: 1000;
    }

    section {
      padding: 50px 20px;
    }
  </style>
</head>
<body>
  <header>
    <h1>Sticky Header</h1>
  </header>

  <section>
    <p>Your website content goes here...</p>
  </section>

  <script>
    window.onscroll = function() {
      const header = document.querySelector('header');
      if (window.scrollY > 50) {
        header.classList.add('sticky');
      } else {
        header.classList.remove('sticky');
      }
    };
  </script>
</body>
</html>
Editor is loading...
Leave a Comment