Isaac Tinoco
Isaac Tinoco

Reputation: 1

I want to make a navbar stick to the top but when I scroll the bar comes down but behind the content

Here is my code:

#nav {
  color: #ffffff;
  display: -moz-flex;
  display: -webkit-flex;
  display: -ms-flex;
  display: flex;
  -moz-transition: -moz-transform 1s ease, opacity 1s ease;
  -webkit-transition: -webkit-transform 1s ease, opacity 1s ease;
  -ms-transition: -ms-transform 1s ease, opacity 1s ease;
  transition: transform 1s ease, opacity 1s ease;
  background: rgba(255, 255, 255, 0.175);
  height: 4rem;
  line-height: 4rem;
  margin: -4rem auto 0 auto;
  overflow: hidden;
  padding: 0 2rem 0 0;
  position: relative;
  width: calc(100% - 4rem);
  max-width: 72rem;
  z-index: 2;
}

#nav ul.links {
  display: -moz-flex;
  display: -webkit-flex;
  display: -ms-flex;
  display: flex;
  -moz-flex-grow: 1;
  -webkit-flex-grow: 1;
  -ms-flex-grow: 1;
  flex-grow: 1;
  -moz-flex-shrink: 1;
  -webkit-flex-shrink: 1;
  -ms-flex-shrink: 1;
  flex-shrink: 1;
  font-family: "Source Sans Pro", Helvetica, sans-serif;
  font-weight: 900;
  letter-spacing: 0.075em;
  list-style: none;
  margin-bottom: 0;
  padding-left: 0;
  text-transform: uppercase;
}

#nav ul.links li {
  display: block;
  padding-left: 0;
}

#nav ul.icons {
  -moz-flex-grow: 0;
  -webkit-flex-grow: 0;
  -ms-flex-grow: 0;
  flex-grow: 0;
  -moz-flex-shrink: 0;
  -webkit-flex-shrink: 0;
  -ms-flex-shrink: 0;
  flex-shrink: 0;
  margin-bottom: 0;
}

@media screen and (max-width: 980px) {
  #nav {
    display: none;
  }
}
<!-- Nav -->
<nav id="nav_bar">
  <ul class="nav_links">
    <li class="active"><a href="index.html" style="Tall Film">Fried Potato</a></li>
    <li><a href="generic.html">Generic Page</a></li>
    <li><a href="elements.html">Elements Reference</a></li>
  </ul>
  <ul class="icons">
    <li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
  </ul>
</nav>

Basically what happened first is that the navbar was not in the center of the page after I figured out that the bar is behind the content.

Upvotes: 0

Views: 45

Answers (1)

ecooper10
ecooper10

Reputation: 107

Have you tried changing:

 position: fixed; 

in #nav?

Upvotes: 1

Related Questions