0

This is the code for my navbar (it has some more details, but it's just style so it doesn't matter I guess), and I cant find anything to make it fixed to the top of the page when I scroll down.

Also I'd like to do a smooth movement whenever I click any of the buttons, but

.container {
  width: 80%;
  margin: 0 auto;
}

header {
  background: black;
}

header::after {
  content: '';
  display: table;
  clear: both;
}

header h3 {
  color: white;
  float: left;
  padding: 10px 0;
}

nav {
  float: right;
}

nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

nav li {
  display: inline-block;
  margin-left: 70px;
  padding-top: 18px;
  position: relative;
}
<header>
  <div class="container">
    <h3>logo</h3>
    <nav>
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#sobre">Sobre</a></li>
        <li><a href="#servico">Serviços</a></li>
        <li><a href="#BaseDeCusto">Base de Custo</a></li>
        <li><a href="#faq">FAQ</a></li>
        <li><a href="#contato">Contato</a></li>
      </ul>
    </nav>
  </div>
</header>
Adam
  • 1,385
  • 1
  • 10
  • 23
  • You might want to read about [position: sticky;](https://developer.mozilla.org/en-US/docs/Web/CSS/position) if you want the navbar to be fixed at the top in visible view of the browser – E. Sundin Apr 30 '18 at 19:58
  • 1
    Possible duplicate of [Smooth scrolling when clicking an anchor link](https://stackoverflow.com/questions/7717527/smooth-scrolling-when-clicking-an-anchor-link) – Adam Apr 30 '18 at 20:15

1 Answers1

1

To do this, you want to give it the property:

header {
    position: fixed;
}
Andrew
  • 65
  • 9