All the Bootstrap's nav components (e.g., tabs and pills) uses the same base markup and styles through the base .nav class. It is important to note that most navs (menus) are created from an unordered bullet list ( <ul> tag) with nested list items ( <li> tags) in of it.
Tab or Pall navs allows large amount of content to be displayed in a small area by separating the content into different panels where only one panel is visible at a time by clicking on the respective tab or pill. Tab or Pill navs also prevents having to create a separate page for each content area.
<body> <ul class="nav nav-tabs">
<li class="active"><a href="#">HTML5</a></li>
<li><a href="#">CSS3</a></li> <li><a href="#">JavaScript</a></li>
</ul>
- The first class nav establishes the <ul> parent tag as a nav container.
- The second class nav-tabs establishes the style of the nav to be tabs as opposed to pills that will be seen later.
- The active class highlights the current tab that is is associated with.
<body> <ul class = "nav nav-tabs">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li>
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li>
</ul>
<body> <ul class = "nav nav-pills">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li>
</ul>
<body> <ul class = "nav nav-pills">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li> <li>
<a href="#">Apps <span></span></a>
<ul>
<li><a href="#">Dreamweaver</a></li>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li class="divider"></li>
<li><a href="#">InDesign</a></li>
</ul>
</li>
</ul>
<body> <ul class = "nav nav-pills">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li>
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li> <li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Apps <span class="caret"></span></a>
<ul class = "dropdown-menu">
<li><a href="#">Dreamweaver</a></li>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li class="divider"></li>
<li class="disabled"><a href="#">InDesign</a></li>
</ul>
</li>
</ul>
Pills / Tabs navigations are laid out horizontally by default. To cause them to be laid out vertically (or stacked), a single class needs to be added to the <ul> tag (nav-stacked).
<body> <ul class = "nav nav-pills nav-stacked">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li>
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li> <li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Apps <span class="caret"></span></a>
<ul class = "dropdown-menu">
<li><a href="#">Dreamweaver</a></li>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li class="divider"></li>
<li class="disabled"><a href="#">InDesign</a></li>
</ul>
</li>
</ul>
<body> <div class="container">
<h1>RMCS: Learning Made Easy</h1>
<div class="row">
<div class="col-md-3">
<h2>HTML5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
</div>
</div>
<body> <div class="container">
<h1>RMCS: Learning Made Easy</h1>
<div class="row">
<div class="col-md-3">
<h2>HTML5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
<h2>CSS3 </h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
<h2>JavaScript </h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
// MENU WILL GO HERE...
</div>
</div>
</div>
<body> <div class="container">
<h1>RMCS: Learning Made Easy</h1>
<div class="row">
<div class="col-md-3">
<h2>HTML5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
<h2>CSS3 </h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
<h2>JavaScript </h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p>
</div>
<div class="col-md-3">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#">Apps</a></li>
<li><a href="#">Dreamweaver</a></li>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
</ul>
</div>
</div>
</div>
To make the tabs or pills nav have equal widths within their parent container, a single class needs to be added to the
<ul>
tag (nav-justified). However, it is important to note that it works only on screens with width greater than 768px. On smaller screens, the nav links are stacked.
<body> <ul class = "nav nav-pills nav-justified">
<li class="active"><a href="#"><span class="glyphicon glyphicon-star"></span> HTML5</a></li>
<li><a href="#"><span class="glyphicon glyphicon-credit-card"></span> CSS3</a></li> <li><a href="#"><span class="glyphicon glyphicon-wrench"></span> JavaScript</a></li> <li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Apps <span class="caret"></span></a
<ul class = "dropdown-menu">
<li><a href="#">Dreamweaver</a></li>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li class="divider"></li>
<li class="disabled"><a href="#">InDesign</a></li>
</ul>
</li>
</ul>
Instead of having a series of tabs or pills that takes a user to another page, you can have them show content on the same page.
<body> <div class="container"> <h2>RMCS: Learning Made Easy</h2> <ul> <li><a href="#HTML5_menu">HTML5</a></li> <li><a href="#CSS3_menu">CSS3</a></li> <li><a href="#JavaScript_menu">JavaScript</a></li> <li>
<a href="#">Apps <span></span></a> <ul>
<li><a href="#Dreamweaver_menu">Dreamweaver</a></li>
<li><a href="#Photoshop_menu">Photoshop</a></li>
<li><a href="#Illustrator_menu">Illustrator</a></li>
<li class="divider"></li>
<li class="disabled"><a data-toggle="tab" href="#InDesign_menu">InDesign</a></li>
</ul>
</li </ul> <div> <div id="HTML5_menu"> <h3>HTML5</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="CSS3_menu"> <h3>CSS3</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="JavaScript_menu"> <h3>JavaScript</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="Dreamweaver_menu"> <h3>Dreamweaver</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="Photoshop_menu"> <h3>Photoshop</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="Illustrator_menu"> <h3>Illustrator</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="InDesign_menu"> <h3>InDesign</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> </div> </div>
<body> <div class="container"> <h2>RMCS: Learning Made Easy</h2> <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#html5_menu">HTML5</a></li> <li><a data-toggle="tab" href="#CSS3_menu">CSS3</a></li> <li><a data-toggle="tab" href="#JavaScript_menu">JavaScript</a></li> <li><a href="#JavaScript_menu">JavaScript</a></li> <li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Apps <span class="caret"></span></a> <ul class="dropdown-menu">
<li><a data-toggle="tab" href="#Dreamweaver_menu">Dreamweaver</a></li>
<li><a data-toggle="tab" href="#Photoshop_menu">Photoshop</a></li>
<li><a data-toggle="tab" href="#Illustrator_menu">Illustrator</a></li>
<li class="divider"></li>
<li class="disabled"><a data-toggle="tab" href="#InDesign_menu">InDesign</a></li>
</ul>
</li> </ul> <div class="tab-content"> <div id="html5_menu" class="tab-pane fade in active"> <h3>HTML5</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="CSS3_menu" class="tab-pane fade"> <h3>CSS3</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="JavaScript_menu" class="tab-pane fade"> <h3>JavaScript</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="Dreamweaver_menu" class="tab-pane fade"> <h3>Dreamweaver</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="Photoshop_menu" class="tab-pane fade"> <h3>Photoshop</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> <div id="InDesign_menu" class="tab-pane fade"> <h3>InDesign</h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti, laborum, voluptates nam incidunt quod facilis tempore quibusdam unde enim corporis debitis ratione tenetur nisi quia ullam dolor quo temporibus maxime.</p> </div> </div> </div>