简体   繁体   中英

Can't hide fixed navbar with z-index

I'm currently trying to create an effect - imagine a fullscreen image which is fixed and will be hidden below the content div on scroll (parallax). Additionally I want the navbar to not move on scroll, hence it's fixed. But I want the navbar to also be hidden below the content div as soon as it's being reached on scroll.

Therefore I've tried to use z-index , but without success. Somehow I'm not able to hide the fixed navbar below the content div.

Header:

<div class="container-fluid position-fixed">

  <div class="row m-0 w-100">

    <div class="col-2 justify-content-center d-flex offset-5">
      <a class="align-self-center" routerLink="">
        <h1>NØREBRO STUDIOS</h1>
      </a>
    </div>

    <div class="col-5 pl-5">
      <ul class="nav justify-content-start">
        <li class="nav-item mr-5">
          <a class="nav-link" routerLink="cases">Work</a>
        </li>
        <li class="nav-item mr-5">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Contact</a>
        </li>
      </ul>
    </div>
  </div>

</div>

CSS:

.container-fluid {
  z-index: 1;
  background-color: transparent;
  padding: 3em 0em;
}

Content (upper-container is supposed to hide the header on scroll):

<div class="container-fluid px-0">
  <app-transparent-header></app-transparent-header>
</div>

<div class="front-image min-vh-100 min-vw-100">
</div>


<div class="container-fluid upper-container">

...


CSS:
.front-image {
  background-image: url("/assets/images/savum/savum-front.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

.upper-container {
  padding: 15em 15em 0em 15em;
  background-color: blue;
}

.container-fluid {
  z-index: 9999;
}

If I understand correctly, you want the header to be hidden but you want the navigation bar to be fixed the top of the screen when you scroll:

.nav-parent { 
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    z-index: 999;
}

Set a parent class over the navigation bar, and assign it those values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM