You may also add a dropdown menu in tabs of Bootstrap plug-in by using the dropdown class. In this tutorial, I will show you how you can add dropdown along with the custom look of the tabs of Bootstrap, including the dropdown menu.
In Bootstrap tabs tutorial, I showed you how simply you can create tabs by using a built-in plug-in in Bootstrap framework.
To add a dropdown menu, you simply need to use a few dropdown related classes as shown in the demo below.
I presumed that you have included the libraries of Bootstrap JS and jQuery along with CSS in the <head> section of web page.
The tab is initiated by using a main <ul> that refers the nav nav-tabs Bootstrap CSS class.
<ul class="nav nav-tabs" role="tablist">
This is followed by <li> items that use the data-toggle=”tab”. The first four tabs are created simply that are Home, Java, C# and MySQL.
The next tab is another <li> that refers the .dropdown class.
1 <li class="dropdown">
This is followed by an <a> tag that uses dropdown-toggle class along with data-toggle=”dropdown”:
1 <a class="dropdown-toggle" data-toggle="dropdown" href="#">Web <b class="caret"></b></a>
After that, another <ul> tag is used to create its menu, so it is using the .dropdown-menu class.
1 <ul class="dropdown-menu">
The menu items in dropdpwn are created just like the first four tabs.
<li><a href="#jquerytab" role="tab" data-toggle="tab">jQuery</a></li>
<li><a href="#bootstab" role="tab" data-toggle="tab">Bootstrap</a></li>
<li><a href="#htmltab" role="tab" data-toggle="tab">HTML</a></li>
And finally, the tab panes are created for these menu items. These are again just like the normal tabs e.g.
<div class="tab-pane" id="bootstab">Bootstrap Content here
That’s it, as for as dropdown menu in tabs is concerned.
The above example is using the default color scheme which is specified in the Bootstrap CSS. In order to customize the look of Bootstrap tabs along with the dropdown menu, you may either write your own classes and refer it in particular tags or simply override the CSS classes related to tabs with Bootstrap’s CSS.
In this demo, I am using the same classes in the <style> tag under <head> section to override the default CSS for tabs.
To give it customized look and feel, I just overridden the default classes in the head section. Following classes are used:
- .nav-tabs > li a
- .nav-tabs > li.active > a
- .nav-tabs > li > a:hover
You can see the complete code of HTML and CSS in the demo page along with its output here.