Copy link to clipboard
Copied
Hello,
I am having an issue with the navbar menu in the collapsed state. I have read a lot of discussions about menu bars, but I am new to bootstrap, so I am doing a lot of learning. I am using a fixed navbar, and have seen this page in the forum with what I think is the same issue, but the code did not work for me. I want to use the fixed navbar so the menu stays at the top of the page. Then when it's collapsed and showing the sandwich icon, I want the menu items to push the content down, not overlap it thus hiding the content in the background. Adding top margin to my content will just create a blank space that the menu drops down on when the sandwich item is clicked, and does not give the pushing down effect that I would like to have.
I found this very recent Adobe forum page that has a basic navbar menu fixed to the top, but is for a different issue. I just copied and pasted it into a new dreamweaver page for a starting point. I only used the code because it was recent and looks to me to be very basic, and that's where I need to start. I copied the code below,
Is there a way to modify the basic code below and have a fixed navbar push content down in the collapsed mode?
Thank you very much!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3.3.7 Starter</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--Bootstrap-->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
/**offset navbar-fixed-top**/
body {padding-top: 55px}
</style>
</head>
<body>
<!--top navbar-->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
<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="#">XYZ Company</a></div>
<!-- add menu items-->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li></ul>
<!-- ADD SEARCH FORM HERE -->
<form class="navbar-form navbar-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
</div>
<!--/end top navbar-->
</nav>
<div class="container">
<div class="row">
PAGE CONTENT GOES HERE....
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
<!--latest jQuery-->
<script src="https://code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<!--Bootstrap-->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
The Bootstrap code above behaves exactly as expected for a fixed-top navba. Owing to how CSS fixed positioning works, a fixed-top navbar is removed from the normal document flow. Thus it has no relationship with other elements on the page.
If you want content to push downward when the mobile menu is expanded, you must remove the fixed class. And also remove the CSS padding-top offset.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3.3.7 Starter</title>
<meta name
...Copy link to clipboard
Copied
The Bootstrap code above behaves exactly as expected for a fixed-top navba. Owing to how CSS fixed positioning works, a fixed-top navbar is removed from the normal document flow. Thus it has no relationship with other elements on the page.
If you want content to push downward when the mobile menu is expanded, you must remove the fixed class. And also remove the CSS padding-top offset.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3.3.7 Starter</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--Bootstrap-->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<!--top navbar-->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1"> <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="#">XYZ Company</a></div>
<!-- add menu items-->
<div class="collapse navbar-collapse" id="navbar1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
</ul>
<!-- ADD SEARCH FORM HERE -->
<form class="navbar-form navbar-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button type="submit" class="btn btn-default"> <span class="glyphicon glyphicon-search"></span> </button>
</span> </div>
</form>
</div>
</div>
<!--/end top navbar-->
</nav>
<div class="container">
<div class="row">
<div class="col-sm-6">
<h3>Heading 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae libero lacus, vel hendrerit nisi! Maecenas quis velit nisl, volutpat viverra felis. Vestibulum luctus mauris sed sem dapibus luctus. Pellentesque aliquet aliquet ligula, et sagittis justo auctor varius. Quisque varius scelerisque nunc eget rhoncus. Aenean tristique enim ut ante dignissim. </p>
<h3>Heading 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae libero lacus, vel hendrerit nisi! Maecenas quis velit nisl, volutpat viverra felis. Vestibulum luctus mauris sed sem dapibus luctus. Pellentesque aliquet aliquet ligula, et sagittis justo auctor varius. Quisque varius scelerisque nunc eget rhoncus. Aenean tristique enim ut ante dignissim. </p>
</div>
<div class="col-sm-6">
<h3>Heading 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae libero lacus, vel hendrerit nisi! Maecenas quis velit nisl, volutpat viverra felis. Vestibulum luctus mauris sed sem dapibus luctus. Pellentesque aliquet aliquet ligula, et sagittis justo auctor varius. Quisque varius scelerisque nunc eget rhoncus. Aenean tristique enim ut ante dignissim. </p>
<h3>Heading 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vitae libero lacus, vel hendrerit nisi! Maecenas quis velit nisl, volutpat viverra felis. Vestibulum luctus mauris sed sem dapibus luctus. Pellentesque aliquet aliquet ligula, et sagittis justo auctor varius. Quisque varius scelerisque nunc eget rhoncus. Aenean tristique enim ut ante dignissim. </p>
</div>
</div>
</div>
<!--latest jQuery-->
<script src="https://code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<!--Bootstrap-->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Nancy O.
Copy link to clipboard
Copied
Hi Nancy, thanks for the answer. Maybe I need to head a different direction, then using the navbar. I see a site like this, and they have the effect I need of a fixed menu and a collapsed menu pushing down content - minus the black top row, but I don't think they use a navbar, so perhaps a custom menu instead.
Thanks again,
Brian
Copy link to clipboard
Copied
That example is not a fixed navigation menu. Why? Because it moves when you scroll the page.
Position: fixed is fixed. It doesn't move -- even when page is scrolled up or down.
I think for what you want -- always collapsed navbar - you need a little custom CSS. Add this to your custom stylesheet. Do not edit Bootstrap CSS.
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
}
.navbar-nav>li {
float: none;
}
.navbar-collapse.collapse.in{
display:block !important;
}
Nancy O.
Copy link to clipboard
Copied
Thank you.