i’m working on upgrading a website so it becomes responsive. I’m using twitter bootstrap. I already tried a couple of different nav bar templates that i found online and i always have the same problem. As you can see in the images in some resolutions the nav bar isn’t collapsing the way it should.
The problem:
The navbar html code:
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="index.htm">Index</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="casameio.htm">casa do meio</a>
</li>
<li><a href="casabrava.htm">casa brava</a>
</li>
<li><a href="casavelha.htm">casa velha</a>
</li>
<li><a href="pool.htm">pool</a>
</li>
<li><a href="prijzen.htm">prijzen</a>
</li>
<li><a href="ons.htm">over ons</a>
</li>
<li><a href="activ.htm">activiteiten</a>
</li>
<li><a href="guestbook.htm">gastenboek</a>
</li>
<li><a href="omgeving.htm">kaartje</a>
</li>
<li><a href="contact.htm">contact</a>
</li>
<li><a href="links.htm">linken</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
I also have this in my css:
@media (min-width: 768px) and (max-width: 991px) {
.navbar-collapse.collapse {
display: none !important;
}
.navbar-collapse.collapse.in {
display: block !important;
}
.navbar-header .collapse, .navbar-toggle {
display:block !important;
}
.navbar-header {
float:none;
}
}
Any help would be appreciated!
2
Answers
It looks like your navigation is fairly wide, so what you could do is simply change when the bootstrap nav collapses. Looking at your code, 1000px seems to be a good breaking point for the collapse to happen, but you can play around with that.
One solution would be to go and add a new media query that will overwite that of Bootstraps. This solution would be fine if you don’t want to edit your bootstrap code directly:
Another, easier option, if you are using LESS is to change the variables that trigger the breakpoint. You could instead use something along these lines:
This is the complete CSS (*taking into account your site structure) if you want to change your breakpoint for the navigation on smaller viewports.
You should also consider moving some of your links into dropdown lists which would allow you to avoid all of this.