-3

I would like to create a fixed header on scroll, similar to this website: www.avauntmagazine.com

This is my html for my header:

<div class="bloc bgc-wild-blue-yonder l-bloc " id="bloc-1">
    <div class="container bloc-sm">
        <div class="row">
            <div class="col">
                <nav class="navbar navbar-light row navbar-expand-md flex-column" role="navigation">
                    <a class="navbar-brand mx-auto" href="index.html">Company</a>
                    <button id="nav-toggle" type="button" class="ui-navbar-toggler navbar-toggler border-0 p-0" data-toggle="collapse" data-target=".navbar-32491" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse navbar-32491">
                        <ul class="site-navigation nav navbar-nav mx-auto justify-content-center">
                            <li class="nav-item">
                                <a href="index.html" class="nav-link">Professional Wedding Planners | Devon</a>
                            </li>
                        </ul>
                    </div>
                </nav>
            </div>
        </div>
    </div>
</div>
Clarke Cribb
  • 249
  • 2
  • 12

3 Answers3

1

Use the position property in CSS:

#bloc-1 {
    position: sticky;
    top: 0;
}
Benoit Esnard
  • 2,017
  • 2
  • 24
  • 32
1

If it were me, I would probably use CSS position sticky. That way it will only sticky to the top once it hits the top of the window.

#bloc-1 {
  position: sticky;
  top: 0;
}
Matt Tanner
  • 305
  • 1
  • 9
0

Look into the affix method - you can do this with some javascript. The Boostrap 4 docs mention using the position: sticky; solution.

Affix is not working in Bootstrap 4 (alpha)

kyle
  • 663
  • 6
  • 16