Product Landing Page - Build a Product Landing Page

I’m trying to get the #nav-bar to the top of the viewport but I don’t how Please I need some hints.

Your code so far

<!-- file: index.html -->
<html>
<head>
<link rel="stylesheet" href="styles.css"/>
</head>
<body>
<header id="header">
  <div>
  <img id="header-img" src="" />
  <nav id="nav-bar">
      <a href="#features" 
class="nav-link">Features</a>
      <a href="#how-it-works" class="nav-link">How it works</a>
      <a href="#pricing" class="nav-link">Pricing</a>
  </nav>
</header>
<iframe id="video" src=""></iframe>
 <form id="form" action="https://www.freecodecamp.com/email-submit">
    <input name="email" type="email" id="email" placeholder="Enter your email" required>
    <input type="submit" value="Submit" id="submit">
  </form>
  <div class="container">
    <section id="features">

    </section>
    <section id="how-it-works"></secton>
    <section id="pricing"></section>
  </div>
</body>
</html>
/* file: styles.css */
html, body {
      height: 100%;
      margin: 0;
      font-family: Arial, sans-serif;
    }

    body {
      display: flex;
      flex-direction: column;
    }

    #header {
      background-color: #333;
      color: white;
      text-align: center;
      padding: 1em;
    }

    #nav-bar {
      display: flex;
      justify-content: space-around;
      background-color: #444;
      padding: 0.5em;
      position: sticky;
      top: 0;
      z-index: 1000;
    }

    .nav-link {
      color: white;
      text-decoration: none;
    }

    #video {
      width: 100%;
      height: 400px;
    }

    #form {
      text-align: center;
      padding: 2em;
    }

    #email {
      padding: 0.5em;
      width: 70%;
      margin-bottom: 1em;
    }

    #submit {
      padding: 0.5em 1em;
      background-color: #333;
      color: white;
      border: none;
      cursor: pointer;
    }

    @media (max-width: 600px) {
      #nav-bar {
        flex-direction: column;
      }
    }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Product Landing Page - Build a Product Landing Page

So with position sticky, the parent element has to be the element with the scroll overflow. Usually, that would be the body element.

One option here is the move the positioning from the nav element to the header element.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.