Is there a way to prevent content from scrolling behind a fixed position element?
Check out the demo here
.navbar-default {
background-color: #4c68f9;
margin-bottom: 0;
border: none;
}
.navbar-default.affix {
background-color: #4762ed;
margin: auto;
right: 0;
left: 0;
transition: all .6s ease-in-out;
}
.navbar-default.affix + .container {
padding-top: 70px;
}
.navbar-default .nav-property,
.navbar-default .navbar-brand,
.navbar-default .navbar-nav > li > a {
color: #fff;
font-weight: bold;
padding: 30px 20px;
}
.navbar-default .navbar-brand {
font-size: 32px;
}
.navbar-default .navbar-brand:hover {
color: #fff;
}
@media screen and (max-width: 767px) {
.navbar-default .navbar-nav {
overflow: hidden;
margin: auto;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin-top: 80px;
}
}
@media (min-width: 768px) {
.navbar-default .navbar-nav > li {
padding: 10px;
}
}
.navbar-default .navbar-nav > li.active a,
.navbar-default .navbar-nav > li.active a:hover {
background-color: transparent;
color: #fff;
}
@media (min-width: 768px) {
.navbar-default .navbar-nav > li.active a:after,
.navbar-default .navbar-nav > li.active a:hover:after {
width: calc(100% - 20px);
}
}
.navbar-default .navbar-nav > li > a {
font-size: 18px;
font-weight: 500;
padding: 20px 10px 10px;
position: relative;
}
@media screen and (max-width: 767px) {
.navbar-default .navbar-nav > li > a {
font-size: 30px;
padding: 20px 10px;
}
}
.navbar-default .navbar-nav > li > a:after {
content: "";
height: 2px;
width: 0;
background-color: #fff;
transition: all .2s ease-in-out;
margin: auto;
position: absolute;
right: 0;
bottom: 0;
left: 0;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #fff;
}
.navbar-default .navbar-nav > li > a:hover:after,…
</div>
</div>
<div class="container">
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nam minus est aliquid tempore hic placeat eligendi corrupti! Aspernatur sint fuga minima, assumenda quo, obcaecati recusandae dolores sequi, eum culpa dicta!</h3>
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus laborum dignissimos blanditiis nostrum at quibusdam neque eum iusto, excepturi cupiditate voluptatibus ipsum, distinctio dolores, quis deleniti architecto libero iure suscipit.</h2>
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim laboriosam repellendus, tempore fugiat, eveniet dolorem quas error. Enim officiis, recusandae, dolorum sed…
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-static-top" data-spy="affix" data-offset-top="1">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse in" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a>
</li>
<li><a href="#">Link</a>
</li>
<li><a href="#">Link</a>
</li>
<li><a href="#">Link</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="container">
<h3>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nam minus est aliquid tempore hic placeat eligendi corrupti! Aspernatur sint fuga minima, assumenda quo, obcaecati recusandae dolores sequi, eum culpa dicta!</h3>
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus laborum dignissimos blanditiis nostrum at quibusdam neque eum iusto, excepturi cupiditate voluptatibus ipsum, distinctio dolores, quis deleniti architecto libero iure suscipit.</h2>
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim laboriosam repellendus, tempore fugiat, eveniet dolorem quas error. Enim officiis, recusandae, dolorum sed…