I can not fix the navbar to the top of the viewport

So hey, I am doing the 4th project from the Responsive Web Design course, and I can not pass the requirement of fixing the nav to the top of the viewport.

<!DOCTYPE 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" />
  <title>Product Landing Page</title>
</head>

<body>
  <div class="container">
    <div class="container">
      <header id="header">
        <div class="container">
          <div class="content">
            <img id="header-img" src="">
            <nav id="nav-bar">
              <a class="nav-link" href="#contacts">Contact</a>
              <a class="nav-link" href="#contacts">Products</a>
              <a class="nav-link" href="#contacts">Services</a>
            </nav>
          </div>
        </div>
      </header>
      <main>
        <div class="container">
          <div class="container">
            <iframe id="video" width="420" height="315" src="https://www.youtube.com/embed/tgbNymZ7vqY">
            </iframe>
            <form id="form" action="https://www.freecodecamp.com/email-submit" method="POST">
              <input id="email" type="email" placeholder="Yeahs" pattern="/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/" name="email">
              <input id="submit" type="submit" value="Submit">
            </form>
          </div>
        </div>
      </main>
      <footer>
        <p id="contacts"></p>
        <p id="products"></p>
        <p id="services"></p>
      </footer>
    </div>
  </div>
</body>

</html>
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  height: 200vh;
}
#header .container .content {
  position: fixed;
  top: 0vw;
}
#nav-bar {
  display: flex;
  position: fixed;
  top: 0;
}

Hey, @csaba20051211. To fix the navbar to the top of the viewport, I would assume that you shouldn’t fix every selector (#header, .container & .content) at the top, just choose one. I would also suggest that you should post your workings on CodePen

Welcome to the community @csaba20051211 !

If you place commas after #header and .container, it will allow the nav-bar to be at the top.

You will just need to add your @media query to complete the project.

I am attaching a link to a fCC News article with guidance for @media queries with examples in case you are unsure.

Keep up the good progress and happy coding!

2 Likes

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