Search code examples
cssheaderfixed

CSS - fixed header gets covered by other divs when scrolling


I'm still learning and completely out of ideas what could be causing this. The header has a fixed position but when I'm scrolling the page the header is not on top and is being covered by some divs.

https://codepen.io/ann9tro/pen/vYpMovj

#header {
  display: flex;
  width: 70vw;
  height: 150px;
  position: fixed;
  left: 50%;
  transform: translate(-50%, 0);
  border: solid 2px #f48d26;
  border-radius: 5px;
  margin: auto;
  justify-content: space-around;
  background-color: white;
}
#center {
  width: 70vw;
  display: flex;
  flex-direction: column;
  text-align: center;
  border: solid 2px #f48d26;
  border-radius: 5px;
  margin: 165px auto 0;
  font-family: Orator Std; 
  background-color: white;
}
#center-pics {
  display: flex;
  justify-content: space-between;
  margin: 40px 100px 20px ;
}
.picture {
  width: 16vw;
  height: 12vw;
  color: black;
  opacity: 0.85;
  border: solid 1px grey;
  border-radius: 5px;
  margin: 30px 0 0 0;
}
<div id="header">
    <img id="header-img" src="https://i.postimg.cc/q7PLWG9j/banner-bez-tla.jpg" alt="company banner with pet faces">
  <nav>
   <ul id="nav-bar">
     <li><a class="nav-link" href="#center">FEATURES</a></li>
     <li><a class="nav-link" href="#quotes">QUOTES</a></li>
   </ul>
  </nav>
  </div>
  <div id="center">
    <div id="center-pics">
      <div class="picture" id="pic1"><p>High quality materials and products</p></div>
      <div class="picture" id="pic2"><p>Tailored for your pet needs</p></div>
      <div class="picture" id="pic3"><p>Pet, human and eco-friendly</p></div>
    </div>
  </div>

Could anyone helop with this please? Thanks!


Solution

  • You should give higher z-index than other div elements to make some element is one top of other element.

    https://codepen.io/joonahn/pen/BaYjqvK

    #header {
      display: flex;
      width: 70vw;
      height: 150px;
      position: fixed;
      left: 50%;
      transform: translate(-50%, 0);
      border: solid 2px #f48d26;
      border-radius: 5px;
      margin: auto;
      justify-content: space-around;
      background-color: white;
      z-index:1000; /* this */
    }