So, in Bootstrap v3, you would just add a data-offset attribute to the nav tag, with the pixel offset, in this case 54px,
<nav data-offset="54"></nav>
However, in Bootstrap v4, this data-offset attribute is missing, and doesn't work. I've had a look through the v4 docs, and just can't seem to find anything! I've also tried using data-offset
and offset
attributes, but these don't work either.
Here is the html code of the nav
<nav class="navbar navbar-light bg-faded navbar-fixed-top">
<button type="button" data-toggle="collapse" data-target="#nav-collapse" aria-controls="#nav-collapse" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler hidden-md-up">☰</button>
<div id="nav-collapse" class="collapse navbar-toggleable-sm">
<ul class="nav navbar-nav pull-md-right">
<li class="nav-item"><a href="#page-top" class="nav-link page-scroll">home</a></li>
<li class="nav-item"><a href="#about" class="nav-link page-scroll">about</a></li>
<li class="nav-item"><a href="#services" class="nav-link page-scroll">services</a></li>
<li class="nav-item"><a href="#productssolutions" class="nav-link page-scroll">products + solutions</a></li>
<li class="nav-item"><a href="#contact" class="nav-link page-scroll">contact</a></li>
</ul>
</div>
</nav>
How would I go about adding a data offset of 54px? Is there an alternative that could be used, say a simple script tag needing to be added to my html with a few lines of js?
data-offset
was used by the Scrollspy component (not specifically the navbar), and hasn't really changed in 4.x. – Bennett50px
which is why body padding is recommended. – Bennett