This code snippet helps you to create a simple fixed navbar in Bootstrap. It uses Bootstrap default navbar template with “navbar-fixed-top” class to make the menu fixed on top of the webpage.
How to Create Simple Fixed Navbar
Create the HTML structure for Bootstrap navbar as follows:
<!-- navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div><!-- /navbar -->
Style using the navbar by adding the following CSS styles to your project:
@import "//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css";
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 60px; /* bottom has to be the same as footer height */
}
footer {
/* just for demo */
background-color: #F8F8F8;
border-top: 1px solid #E7E7E7;
text-align:center;
padding:20px;
/* just for demo */
position: absolute;
left: 0;
bottom: 0;
height: 60px;
width: 100%;
}
That’s all! hopefully, you have successfully created a simple fixed navbar. If you have any questions or suggestions, feel free to comment below.
