Product Landing Page - Build a Product Landing Page

Tell us what’s happening:

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

how do i get my nav-bar to the top
Replace these two sentences with your copied code.
Please leave the line above and the line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge: Product Landing Page - Build a Product Landing Page

Link to the challenge:

Hi,
Can you please share your html and css code? Then I can take a look at it.
:slight_smile:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <meta charset="UTF-8"/>
    <link rel="stylesheet"href="styles.css">
  </head>
  <body>
    <div class="page-wrapper">
      <header id="header">
        <img id="header-img"src="https://cdn.freecodecamp.org/testable-projects-fcc/images/product-landing-page-logo.png"alt="Trombones logo"/>
        <nav id="nav-bar">
          <ul>
            <li><a class="nav-link"href="#features">Features</a></li>
             <li ><a class="nav-link"href="#how it works">How it works</a></li>
              <li><a class="nav-link"href="#pricing">Pricing</a></li>
          </ul>
        </nav>
       
      </header>
#header-img{
  width: 100%;
}

@media (max-width: 600px){
  #nav-bar{
    margin: 10px;
  }
}

.nav-link{
  font-size: 16px
}
nav>ul{
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}


header{
  top: 0;
  left:0;
  
}
ul{
  margin: 0;
  padding: 0;
  display: flex;
}

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Take a look at this w3schools article. It explains how the css position property works.

One of these will let you fix your navbar to the top of the page using css.

i still didnt get it

What don’t you get specifically? Have you changed your code?

Please try to explain yourself in more detail in future. It is important in coding to make sure other coders know exactly what you need help with.

Also, if you want to reply directly to someone, so they are notified of your reply, press the button that says ‘reply’ with a left pointing arrow next to it.

when i fixed the position of the nav-bar the header scattered, please what should i do

Can you please show me your code? :slight_smile:
I won’t be able help if I can’t look at it to see what’s happening.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <meta charset="UTF-8"/>
    <link rel="stylesheet"href="styles.css">
  </head>
  <body>
    <div class="page-wrapper">
      <header id="header">
        <img id="header-img"src="https://cdn.freecodecamp.org/testable-projects-fcc/images/product-landing-page-logo.png"alt="Trombones logo"/>
        <nav id="nav-bar">
          <ul>
            <li><a class="nav-link"href="#features">Features</a></li>
             <li ><a class="nav-link"href="#how it works">How it works</a></li>
              <li><a class="nav-link"href="#pricing">Pricing</a></li>
          </ul>
        </nav>
       
      </header>
      <div class="container">
      <section id="hero">
        <h2>Handcrafted, home-made masterpieces</h2>
        <form id="form"action="https://www.freecodecamp.com/email-submit">
        <input id="email"type="email"name="email"placeholder="Enter your e-mail address"/>
        <input id="submit" type="submit"name="submit"value="Get started"/>
        </form>
      </section></div>
      <div class="container">
        <section id="features">
          <div class="life">
            <div class="icon"><i class="fa fa-3x fa-fire"><i></div>
            <div class="description">
              <h2>
Premium Materials</h2>
<p>Our trombones use the shiniest brass which is sourced locally. This will increase the longevity of your purchase</p>
            </div>
            </div>
            <div class="life">
              <div class="icon"><i class="fa fa-3x fa-truck"><i></div>
              <div class="description">
                <h2>
Fast Shipping</h2>
<p>We make sure you recieve your trombone as soon as we have finished making it. We also provide free returns if you are not satisfied.</p>
              </div>
            </div>
            <div class="life">
              <div class="icon"><i class="fa fa-3x fa-battery-full"></i></div>
              <h2>
Quality Assurance</h2>
<p>For every purchase you make, we will ensure there are no damages or faults and we will check and test the pitch of your instrument.</p>
            </div>
        </section>
      </div>
      <div class="container">
        <section id ="how it works">
          <iframe id ="video"height="315"src="https://www.youtube-nocookie.com/embed/y8Yv4pnO7qc?rel=0&amp;controls=0&amp;showinfo=0"frameborder="0"></iframe>
        </section>
      </div>
      <div class="container">
        <section id ="pricing">
          <div class="product" id="tenor">
            <div class="level">TENOR TROMBONE</div>
            <h2>$500</h2>
            <ol>
             <li>Available</li> 
               <li>Available</li>
                 <li>Available</li>
            </ol>
            <button class="select">Select</button>
          </div>

          <div class="product"id="bass"
                   <div class="level">BASS TROMBONE</div>
            <h2>$900</h2>
            <ol>
             <li>Available</li> 
               <li>Available</li>
                 <li>Available</li>
            </ol>
            <button class="select">Select</button>
          </div>
     
     <div class="product"id="Valve"
                   <div class="level">VALVE TROMBONE</div>
            <h2>$1000</h2>
            <ol>
             <li>Available</li> 
               <li>Available</li>
                 <li>Available</li>
            </ol>
            <button class="select">Select</button>
          </div>
        </section>
      </div>

  </body>
</html>

Can you share your css too please?

#header-img{
  width: 100%;
  justify-content: left;
}

@media (max-width: 600px){
  #nav-bar{
    margin: 10px;
  }
}

.nav-link{
  font-size: 16px
}
nav>ul{
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

I can’t see a position:fixed in this css code. Can you explain what you mean by fixing in this case?

You will also have to explain in more detail what you mean by ‘scattered’. I’ve got your code loaded on codepen to test and this is what I see.

Can you explain what the header should look like visually instead? Then I can see what we can do with your code to achieve that.

Also, keep an eye on your elements. Some divs are unclosed in your html. This will cause unexpected visual issues.

<div class="level">BASS TROMBONE</div>

#header-img{
  width: 100%;
  justify-content: left;
}

@media (max-width: 600px){
  #nav-bar{
    margin: 10px;
  }
}

.nav-link{
  font-size: 16px
}
nav>ul{
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}
#nav-bar{
  position: fixed;
}

Right. The issue here is how position:fixed affects nested elements.

So let’s look at your html navbar structure.

<header id="header">
        <img id="header-img"src="https://cdn.freecodecamp.org/testable-projects-fcc/images/product-landing-page-logo.png"alt="Trombones logo"/>
        <nav id="nav-bar">
          <ul>
            <li><a class="nav-link"href="#features">Features</a></li>
             <li ><a class="nav-link"href="#how it works">How it works</a></li>
              <li><a class="nav-link"href="#pricing">Pricing</a></li>
          </ul>
        </nav>
       
      </header>

The position:fixed is applied to your #nav-bar, this means everything inside the #nav-bar will stick to the top of the screen.

But you’ve got elements like the img that are not inside #nav-bar, they are inside the header element. So they are not affected by position:fixed and will not move with the rest of the navigation menu content.

Which element that contains all your nav-links and header image could have position:fixed applied to it so everything in your navigation menu sticks to the top of the screen?

1 Like

Thank you very much for your help, I have corrected my errors.

1 Like