1

I am trying to make my navigation bar scroll with the website so it is visible at all times.

When testing this locally, it works perfectly for mobile and desktop. However, when I published this code live on my website the nav bar doesn't follow the scroll (only on mobile). I thought I was missing the position:sticky attribute below the media tag, but that didn't seem to fix it either. Any help anyone can offer would be great, I'm very new to this so I might be missing something obvious. Also if there is an easier way to do this entirely, let me know.

Here's my CSS and HTML:

.nav-toggle{
  border-bottom: 1px solid #EAEAEB;
  text-align: right;
  height: auto;
  min-height: 4rem;
  line-height: 4rem;
  position: sticky;
  top: 0;
  display:block;
  width: 100%;
  background-color: #ffffff;
  z-index: 2;
}

.links{
  float: right;
  background-color: #ffffff;
  padding-right: 69px;
}

.links a{
  text-decoration: none;
  font-family: 'Open Sans', sans-serif;
  color:#58606C;
  line-height: 4rem;
}

label {
  font-size: 26px;
  line-height: 70px;
  margin-right: 40px;
  display: none;
  color: #63C3EF;
}



#toggle{
  display: none;

}

.logo-mobile { 
  display: block;
  float: left;
  width: 48px;
  margin-left:120px;
  line-height: 4rem;
}


@media only screen and (max-width: 700px) {

.nav-toggle{
  position: sticky;
  top: 0;
}
  label {
    display: block;
    cursor: pointer;
    width: 26px;
    float: right;
    margin-right: 15px;
  }

  .logo-mobile{
    width: 35px;
    height: 35px;
    line-height: 4rem;
    display: block;
    float: left;
    margin-left: 15px;
    padding-top: 15px; 
}

  .links{
    text-align: center;
    width: 100%;
    display: none;
    padding-right: 0;
  }

  .links a {
    clear: right;
    display: block;
    border-bottom: 1px solid #EAEAEB;
    margin: 0;
  }

  .links .current { /*the state when the link is active*/
  color: #63C3EF;
}
}

#toggle:checked + .links {
  display: block;
}
<div class="nav-toggle">
    <a href="index.html" class="logo-mobile"> <img src="images/logom@2x.png" alt="KM"></a>
    <label for="toggle">&#9776;</label>
    <input type="checkbox" id="toggle"/>
    <div class="links">
      <a href="work.html">Work</a>
      <a href="about.html">About</a>
    </div>
   </div>
TylerH
  • 20,799
  • 66
  • 75
  • 101

0 Answers0