0

I'm designing a sticky top navbar for my website, I've followed the documentation provided by Bootstrap on their website and looked at previously asked questions on here but I can't get my head round on why its not working. Any help would be great

        <!DOCTYPE html>

        <html>


<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
    <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="about.html">ABOUT</a>
            </li>


            <li class="nav-item">
                <a class="nav-link" href="#">CLOTHING</a>
            </li>


            <li class="nav-item">
                <a class="nav-link" href="#">CLOTHING</a>
            </li>


        </ul>
    </div>
</nav>






    </body>
    </html>

CSS

.navbar {
    background-color: #2A2F35 !important;
    padding: 0 !important;
}

/*Navbar Links*/

.navbar-nav a {
    font-family: 'Open Sans', sans-serif;
    font-style: normal;
    font-size: 16px;
    font-weight: 100;
    letter-spacing: 1px;
    color: #ffffff !important;
    padding: 25px;
    margin: 0px 25px 0px 25px;
}

.navbar-nav a:hover {
    color: #ff6600 !important;
}
Will_Ghost16
  • 81
  • 2
  • 11

5 Answers5

0
<nav class="navbar **fixed-top** navbar-light bg-light">

'fixed-top' doesn't seem to be in the nav class.

Jitrenka
  • 185
  • 1
  • 10
0
<nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar-fixed-top"></nav>

Use navbar-fixed-top instead of sticky-top

Candy
  • 654
  • 2
  • 10
  • 24
0

The following Code Works perfectly once you import bootstrap 4

.navbar {
    background-color: #2A2F35 !important;
    padding: 0 !important;
}

/*Navbar Links*/

.navbar-nav a {
    font-family: 'Open Sans', sans-serif;
    font-style: normal;
    font-size: 16px;
    font-weight: 100;
    letter-spacing: 1px;
    color: #ffffff !important;
    padding: 25px;
    margin: 0px 25px 0px 25px;
}

.navbar-nav a:hover {
    color: #ff6600 !important;
}
.height{
border:1px solid red;
min-height:500px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<!--Nav bar Starts-->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
  <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="about.html">ABOUT</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">CLOTHING</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">CLOTHING</a>
      </li>
    </ul>
  </div>
</nav>
<div class="height">

</div>
Gowtham
  • 1,557
  • 12
  • 24
-1

Add below lines in your css. As stikcy-top class definition is missing

width: 100%;
position: fixed;
top: 0;

target this classes: class="navbar navbar-inverse navbar sticky-top"

Crypt32
  • 12,850
  • 2
  • 41
  • 70
pooja
  • 1
  • 4
  • Welcome to Stack Overflow! It would be great, if you could a little bit of an explanation to your answer about why the code you're suggesting should fix the problem described in the question. – anothernode Jun 18 '18 at 10:37
-1

This is an old one, but just in case someone runs into the same problem, when the suggested Bootstrap 4 sticky nav does not work, one more thing to check is if any parent element has one of these css properties set:

overflow overflow-y overflow-x

If this property is set to one of these vales it will NOT work: auto, hidden, overlay, scroll.

Just remove it or change its value to 'unset'. Look for the parent elements using DevTools

enter image description here

diego sanches
  • 944
  • 9
  • 8