Kait Jardine
Kait Jardine

Reputation: 103

Bootstrap sticky-top navbar disappearing on scroll

The navbar sticks to the top until I scroll out of the hero-image then disappears. I'd like the navbar to be present throughout the whole page. Any ideas?

<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="#home">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#about">About Me</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#projects">Projects</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#contact">Contact Me</a>
                </li>
            </ul>
        </div>
    </nav>
<!--Navbar end-->

<!-- Homescreen hero -->
    <div class="hero-image" id="home">
        <div class="hero-text">
            <h1 class="name">Text</h1>
            <h1>Text</h1>
        </div>
    </div>

Upvotes: 2

Views: 5425

Answers (2)

Deevoid
Deevoid

Reputation: 111

Just remove any height declaration from the body tag in your css.

e.g. Remove things like this:

body { height 100 vh or %;}

Edit: Also make sure to give top:0 to your sticky navbar element

Upvotes: 6

Tibbelit
Tibbelit

Reputation: 1335

You can try to use fixed-top instead of sticky-top.

I don't know which browser you're using, but the documentation states Also note that .sticky-top uses position: sticky, which isn’t fully supported in every browser.(https://getbootstrap.com/docs/4.2/components/navbar/#placement)

Upvotes: 4

Related Questions