navbar-fixed-top show content behind Navbar

Chris G. picture Chris G. · Sep 1, 2015 · Viewed 14.1k times · Source

How do you prevent the content from floating behind the Navbar when scrolling?

<Navbar className="navbar-form navbar-fixed-top" responsive collapseable brand='x' inverse toggleNavKey={1} onClick={this.handleMouseDown}>

Or is it in:

<Nav className="navigation"..

Thanks

Answer

Scrotch picture Scrotch · Jul 4, 2018

I like jmarceli's answer, but here's a simpler approach:

Add a custom class to your navbar component, say, sticky-nav. Define the following CSS properties on it:

.sticky-nav {
  position: sticky;
  top: 0;
}

This will make your navbar stick to the top and will automatically adjust the height of its following DOM elements. You can read more about the sticky property on MDN.