Reputation: 26467
How do people typically style the output of the Twitter Bootstrap collapsible navigation?
The standard structure is as follows.
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="brand">Project name</a>
<div class="nav-collapse collapse">
<ul class="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><!--/.nav-collapse -->
</div>
</div>
</div>
For example, if I would like to style .nav li a
, I can do so with that CSS selector, but that also then changes the styling of the mobile navigation. Bootstrap doesn't appear to add any useful combination of classes to denote different ones.
<div class="nav-collapse collapse"> <!-- Closed by button -->
<div class="nav-collapse on collapse"> <!-- Open by button -->
<div class="nav-collapse on collapse"> <!-- Closed by resizing window to > mobile -->
I find myself having to effectively implement the bootstrap styles again for the mobile version because I can't seem to find a combination of classes which allows me to style just the main nav rather than the dropdown. For example, the dropdown can be styled with .nav-collapse.on
This is probably a really simple thing to do but can't seem to work it out!
Upvotes: 0
Views: 849
Reputation: 17
The menu is broken into two parts, a structure and a styling. If you remove the styling you are left with a naked bootstrap menu that is easy to style. Remove the "navbar-inner" call and it will strip out all the styling for you. I just rename the call on the menu div from navbar-innner to navbar-inner_OFF. That shuts off the -inner css and also reminds me I rurned it off when I look at the menu code.
Upvotes: 0
Reputation: 4773
I have delt with this issue myself and there are range of solutions.
In order I would put them something like:
Upvotes: 1
Reputation: 158
Simplest solution would be to wrap the .navbar div for your main nav in a div with a custom class -- like, say, "mainnav". Then you can write styles to things like ".mainnav .nav li a".
If you can touch the bootstrap structure itself, you could skip the wrapper div and simply add the class "mainnav" to the "navbar" div, and then write styles like ".mainnav.navbar .nav li a".
Upvotes: 0