I want to show you how to create a twitter like navigation topbar in few minutes using Bootstrap.
“Bootstrap is a toolkit from Twitter designed to kickstart development of webapps and sites.
It includes base CSS and HTML for typography, forms, buttons, tables, grids, navigation, and more.”
As usual I am going to show you the code using Mootools or jQuery.
The html code that you need to add at your page is the same in both cases:
<div class="topbar" id="topbar">
<div class="fill">
<div class="container">
<a class="brand" href="#">Project name</a>
<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>
<ul class="nav secondary-nav">
<li class="menu">
<a href="#" class="menu">mconventi</a>
<ul class="menu-dropdown">
<li><a href="#">Settings</a></li>
<li><a href="#">Help</a></li>
<li class="divider"></li>
<li><a href="#">Sign out</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
You need to add the stylesheet given by Bootstrap (you can start from it then you can download the uncompressed file to customize it).
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
If you want to use jQuery all you need is to add jQuery, bootstrap-dropdown.js and call the dropdown function on the topbar:
<script src="<your_path_here>/jquery-1.7.1.min.js"></script>
<script src="<your_path_here>/bootstrap-dropdown.js"></script>
<script>
$(window).load(function(){
$('#topbar').dropdown();
});
</script>
If you prefer Mootools you need to add the core library, the element shortcuts and the classes Bootstrap and Bootstrap.Dropdown:
<script src="<your_path_here>/mootools-core-1.4.2.js"></script>
<script src="<your_path_here>/mootools-element.shortcuts-1.4.0.1.js"></script>
<script src="<your_path_here>/Bootstrap.js"></script>
<script src="<your_path_here>/Bootstrap.Dropdown.js"></script>
<script>
window.addEvent('domready', function(){
new Bootstrap.Dropdown($('topbar'));
});
</script>
Here a demo of what you get
Thanks to Twitter to have released the Bootstrap toolkit and to Aaron Newton for the “MooTools for Bootstrap” library.
Personally I think that the Bootstrap toolkit can be really useful, it contains other interesting features that I hope to show you soon. Let me know what do you think about this post, thanks








stavo giusto facendo alcuni test con questo menu..ma trovo un problema ad inserire la riga di separzione con la classe:
viene inserita dal menu di wp?
Ciao e grazie per aver visitato il mio blog! Se vuoi puoi scaricare un esempio completo da questo nuovo articolo http://www.maurizioconventi.com/2012/02/08/responsive-web-design-with-twitter-bootstrap/ potresti avere dei problemi perchè la versione del toolkit usata in questo post è vecchia.
Fammi sapere,
Maurizio
credo di non aver sposto bene il mio problema :-/
dal menu di WP io vado ad aggiungere le varie pagine, per fare il dropdown in custom links uso ” # ” e fin qui tutto ok… giusto? quando invece voglio inserire la riga orizzontale per dividere invece come faccio? che basterebbe far prendere…la classe=”divider”
Si, se ti serve giusto un riga per separare i link puoi usare un elemento li con class=”divider”
ho risolto oggi… un sistema un po elaborato ma funziona bene.
Ho pubblicato come quí http://j8z.eu/naVcls se hai un’altra soluzione per l’inserimento della classe “divider” fammi sapere. Ciao