Hit enter after type your search item

Bootstrap: Adding dropdown menu in Tabs example with code

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.

Bootstrap tabs dropdown basic

See online demo and code

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.


 

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.


 

This is followed by an <a> tag that uses dropdown-toggle class along with data-toggle=”dropdown”:


 

After that, another <ul> tag is used to create its menu, so it is using the .dropdown-menu class.


 

The menu items in dropdpwn are created just like the first four tabs.

 


 

And finally, the tab panes are created for these menu items. These are again just like the normal tabs e.g.


 

That’s it, as for as dropdown menu in tabs is concerned.

Dropdown menu with customized CSS

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.

Bootstrap tabs dropdown

See online demo and code

To give it customized look and feel, I just overridden the default classes in the head section. Following classes are used:

  • .nav-tabs
  • .nav-tabs > li a
  • .nav-tabs > li.active > a
  • .nav-tabs > li > a:hover
  • .tab-pane

You can see the complete code of HTML and CSS in the demo page along with its output here.

This div height required for enabling the sticky sidebar