Product Landing Page nav-bar question


Am trying to keep the nav-bar position as fixed but its having an after effect of my first sections header going behind the nav-bar

/* file: index.html */
<!DOCTYPE html>
  <meta charset='utf-8'>
  <meta name='viewport' content='device-width initial-scale=1.0'/>
  <link rel='stylesheet' href='styles.css'/>

  <header id='header'> 
    <img src='' width='60'
    <nav id='nav-bar'>
        <li ><a href='#Specs' class='nav-link'>Specs</a></li>
        <li><a href='#video' class='nav-link'>Games</a></li>
        <li><a href='#pricing' class='nav-link'>Pricing</a></li>
      <h2>Welcome to Our Storefront</h2>
      <form action='' id='form'>
          <legend for='email'>Sign up for the latest info on our new console</legend>
          <input type='email' id='email' placeholder='please enter your email here' name='email'>
          <input type='submit' value='Get Started' id='submit'>

   <section id='Specs'>
     <h2>Xbox Series X Specifications</h2>
         <p>CPU. 8X Cores @ 3.8 GHz (3.66 GHz w/SMT) Custom Zen 2 CPU</p>

         <h3>MEMORY & STORAGE</h3>
         <p> Memory. 16GB GDDR6 w/320 bit-wide bus</p>
         <h3>VIDEO CAPABILITIES</h3>
         <p> Gaming Resolution. True 4K</li>
         <h3>SOUND CAPABILITIES</h3>
         <p>Dolby Digital 5.1 
            DTS 5.1</p>
          <h3>PORTS & CONNECTIVITY</h3>
          <p>HDMI. 1x HDMI 2.1 port

USB. 3x USB 3.1 Gen 1 ports

Wireless. 802.11ac dual band</p>

     <iframe id='video' width="560" height="315" src=""></iframe>
   <div id='pricing' class='container'>
     <section id='XSS' class='console'>
       <h2>Xbox Series S</h2>
     <section id='XSX' class='console'>
       <h2>Xbox Series X</h2>


/* file: styles.css */

display: flex;
flex-direction: row;
justify-content: space-between;
position: fixed;
background: green;
width: 100%;


nav > ul{
display: flex;
margin-right: 5px;


list-style: none;


text-decoration: none;
ul > li{
margin-right: 40px;

display: flex;
justify-content: space-evenly;
align-items: center;

background-color: #e6e600;
margin: auto;
text-align: center;
height: 150px;
width: 170px;


@media -

  **Your browser information:**

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

Challenge: Build a Product Landing Page

Link to the challenge:

You can make the header stretch completely from side to side and also touch the top of the page and then you won’t see the text underneath as you scroll. One way to do this would be to get rid of the default margins on the body which will make it touch the sides. And then you can make it touch the top by setting top: 0.

1 Like

An element with position: fixed is removed from the normal flow and positioned relative to the viewport. This means that your main element is now the one at the top of the flow, which overlaps with the fixed position of the header. To solve this, you can simply add top padding to your main element.

Alternatively, you can also use position:sticky. position:sticky automatically switches between relative and fixed based on your scroll position. Since relative keeps the element in the normal flow, this means that header will stay in the normal flow of document (above main element) when you have not reached the scroll threshold.

If using position:sticky, remember to also specify a threshold in your css (any one or more of top, right, bottom, left) to indicate at which position, the switch between fixed and relative should happen.

Thanks for the detailed explanation !
I got it now :3

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