I have a website that is made with Twitter Bootstrap. On a large screen the navbar is looking nice as it should be but if you see the same navbar on a cellphone the navbar won't collapse.
This is my code:
<div class="container">
<div class="masthead">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active"><a href="/" class="">Home</a></li>
<li><a href="goud-zilver.html">Oud goud en zilver</a></li>
<li><a href="koersen.html">Officiële koersen</a></li>
<li><a href="webshop/" target="_blank">Webwinkel</a></li>
<li><a href="diversen.html">Diversen</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
</div>
</div><!-- /.navbar -->
</div>
On the third class i also tried to use nav-collapse but then it is also collapsed on a large screen.
To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".
Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin. Navbars are hidden by default when printing. Force them to be printed by adding .
ml-auto class of Bootstrap 4 to align navbar items to the right. The . ml-auto class automatically gives a left margin and shifts navbar items to the right.
Two navbars are placed one after the other. The first navbar has a dark background and the navigation links are left-aligned whereas the “Register” and “Logout” buttons are right-aligned. The first navbar also consists of a dropdown menu that has links to several sections of the website.
Yes follow the instructions from Betty St (include responsive css, bootstrap-collapse.js and the Transitions plugin update: (bootstrap-transition.js) and jQuery). You need to add a button / link which triggers the collapse. This tags get the attributes: data-toggle="collapse" data-target=".nav-collapse" where data-target can be any css selector. Put your nav between the tag selected under data-target, see: http://bootply.com/62921
html:
<div class="container">
<div class="masthead">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="/" class="">Home</a></li>
<li><a href="goud-zilver.html">Oud goud en zilver</a></li>
<li><a href="koersen.html">Officiële koersen</a></li>
<li><a href="webshop/" target="_blank">Webwinkel</a></li>
<li><a href="diversen.html">Diversen</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
</div>
</div>
</div><!-- /.navbar -->
</div>
</div>
update Your code is missing the Transitions plugin (bootstrap-transition.js) required by the Collapse plugin. More important you didn't include jQuery. Now it should work see: http://plnkr.co/l66QqCftGNsaG0xkBrUf
javascript includes:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://twitter.github.io/bootstrap/assets/js/bootstrap-transition.js"></script>
<script type="text/javascript" src="http://twitter.github.io/bootstrap/assets/js/bootstrap-collapse.js"></script>
Note: Consider to include the compiled (or minified) version of the complete javascripts:
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
You also need to change the style after collapsing:
.navbar .in .nav li {
display: block;
float: none;
width:100%;
}
I had the similar kind of problem. I was totally confused of why my navigation bar is not collapsing in mobile phone. Atlast I found that I missed the following meta tag.
<meta name="viewport" content="width=device-width, user-scalable=false;">
This will solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With