Recently, I encountered an issue while developing a new website in Firefox. After a few days, I realized that Bootstrap affix was not working properly in Chrome, IE, and Edge. I am using the latest versions of Bootstrap, Firefox, and Chrome, but I am unsure about the IE version.
I have tried several workarounds, but none of them seem to be effective.
CSS:
.affix {
top: 0;
width: 100%;
}
.affix + .container-fluid {
padding-top: 0px;
}
.affix-bottom {
position: absolute;
}
HTML:
<body data-spy="scroll" data-target="#myScrollspy" data-offset="20">
<div id="scroll"> ....
</div>
<!-- Navbar -->
<div id="nav">
<div class="navbar navbar-inverse navbar-static-top" style="background: #26292E none repeat scroll 0% 0%;border-color: #DE5E60;">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a href="#" class="navbar-brand">Brand</a>
<a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="glyphicon glyphicon-bar"></span>
<span class="glyphicon glyphicon-bar"></span>
<span class="glyphicon glyphicon-bar"></span>
</a>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
</ul>
<ul class="nav pull-right navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<i class="glyphicon glyphicon-user"></i>
Sign In
</a>
<div class="dropdown-menu form-login stop-propagation" role="menu">
<div class="form-group">
<label for="exampleInputEmail1">
<i class="glyphicon glyphicon-envelope"></i>
Email address
</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">
<i class="glyphicon glyphicon-lock"></i>
Password
</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" />
</div>
<a id="contact-submit" class="submit" href="#">Submit</a>
</div>
</li>
</ul>
<ul class="nav pull-right navbar-nav">
<li>
<form class="navbar-form">
<input class="form-control" placeholder="Search" type="text" />
<button type="submit" class="btn btn-default">
<i class="glyphicon glyphicon-search"></i>
</button>
</form>
</li>
<li>
<a href="#">
<span class="badge">2</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- /.navbar -->
</div>
<!-- End Navbar -->
JS:
$('#nav').affix({
offset: {
top: $('#scroll').height()
}
});