Bootstrap Components

Bootstrap Tabs

Introduction

Sometimes it’s quite useful if we can just place a few segments of info sharing the same space on the page so the visitor easily could browse through them without actually leaving the screen. This gets easily achieved in the new fourth version of the Bootstrap framework with the help of the .nav and .tab- * classes. With them you can easily create a tabbed panel with a different types of the content held inside each tab allowing the user to just click on the tab and get to view the desired content. Let’s take a closer look and see how it’s done.

The best way to make use of the Bootstrap tabs:

First of all for our tabbed panel we’ll need some tabs. In order to get one create an <ul> element, assign it the .nav and .nav-tabs classes and place some <li> elements inside carrying the .nav-item class. Inside of these list the actual link elements should take place with the .nav-link class assigned to them. One of the links – usually the first should also have the class .active since it will represent the tab being currently open when the page gets loaded. The links also need to be assigned the data-toggle = “tab” property and each one should target the appropriate tab panel you would want displayed with its ID – for example href = “#MyPanel-ID”

What’s new in the Bootstrap 4 framework are the .nav-item and .nav-link classes. Also in the previous version the .active class was assigned to the <li> element while now it get assigned to the link itself.

Now once the tabs structure has been prepared it’s time for creating the panels holding the actual content to be displayed. First we need a master wrapper <div> element with the .tab-content class assigned to it. Inside of this element a few elements carrying the .tab-pane class should take place. It also is a good idea to add the class .fade in order to assure fluent transition when switching between the tabs. The element which will be displayed by on a page load should also carry the .active class and in case you go for the fading transition - .in along with the .fade class. Each .tab-panel should have a unique ID attribute which will be used for linking the tab links to it – like id = ”#MyPanel-ID” to match the example link from above.

You can also create tabbed panels using a button – like appearance for the tabs themselves. These are also referred as pills. To do it just make sure instead of .nav-tabs you assign the .nav-pills class to the .nav element and the .nav-link links have data-toggle = “pill” instead of data-toggle = “tab” attribute.

Nav-tabs tactics

$().tab

Turns on a tab component and content container. Tab should have either a data-target or an href targeting a container node inside of the DOM.

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item">
    <a class="nav-link active" data-toggle="tab" href="#home" role="tab" aria-controls="home">Home</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" data-toggle="tab" href="#profile" role="tab" aria-controls="profile">Profile</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" data-toggle="tab" href="#messages" role="tab" aria-controls="messages">Messages</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" data-toggle="tab" href="#settings" role="tab" aria-controls="settings">Settings</a>
  </li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="home" role="tabpanel">...</div>
  <div class="tab-pane" id="profile" role="tabpanel">...</div>
  <div class="tab-pane" id="messages" role="tabpanel">...</div>
  <div class="tab-pane" id="settings" role="tabpanel">...</div>
</div>

<script>
  $(function () 
    $('#myTab a:last').tab('show')
  )
</script>

.tab(‘show’)

Chooses the provided tab and gives its connected pane. Any other tab which was previously picked becomes unselected and its associated pane is covered. Come backs to the caller before the tab pane has really been revealed (i.e. right before the shown.bs.tab activity happens).

$('#someTab').tab('show')

Events

When showing a brand-new tab, the events fire in the following ordination:

1. hide.bs.tab ( on the present active tab).

2. show.bs.tab ( on the to-be-shown tab).

3. hidden.bs.tab ( on the previous active tab, the very same one when it comes to the hide.bs.tab event).

4. shown.bs.tab ( on the newly-active just-shown tab, the same one when it comes to the show.bs.tab event).

In the event that no tab was readily active, then the hide.bs.tab and hidden.bs.tab events will not be fired.

Events
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) 
  e.target // newly activated tab
  e.relatedTarget // previous active tab
)

Conclusions

Well basically that’s the way the tabbed panels get created with the latest Bootstrap 4 version. A thing to pay attention for when creating them is that the different contents wrapped inside each tab panel should be more or less the same size. This will help you avoid some “jumpy” behavior of your page when it has been already scrolled to a specific position, the visitor has started browsing through the tabs and at a certain point gets to open a tab with significantly more content then the one being seen right before it.

Review some video clip tutorials regarding Bootstrap tabs:

Related topics:

Bootstrap Nav-tabs: approved documents

Bootstrap Nav-tabs:official  records

Exactly how to turn off Bootstrap 4 tab pane

 Exactly how to close Bootstrap 4 tab pane

Bootstrap 4 Left Stacked Tabs

Bootstrap 4 Left Stacked Tabs

Best Free AI Website Builder

Generate AI websites with a simple prompt! Type in any language, export in zip.


AI Website Builder



Best Free Website Builder Software

Create awesome websites offline! No coding. 9900+ templates. Edit and save locally, upload wherever.


Free website builder download for Win, Mac, Linux!



Best Website Templates

HTML Business Templates

HTML Business Templates

Web Design HTML Templates

Web Design HTML Templates

HTML eCommerce Website Template

HTML eCommerce Website Template

Hotel HTML Template

Hotel HTML Template

Landing Page HTML Template

Landing Page HTML Template

Premium Design HTML Themes

Premium Design HTML Themes

HTML Resume Template

HTML Resume Template

Online Shopping HTML Template

Online Shopping HTML Template

HTML Responsive Templates

HTML Responsive Templates

Latest Posts

  1. AI website creator and generator - how to create a website with AI in just 2 minutes.
  2. Best Free AI website generator and builder - create a website design with AI.
  3. Best Website Builder AIBest Free AI Website Builder - Create Website Design with AI
  4. Best Website Builder for Consultants, Magazines, Churches, Authors
  5. Best Website Builder for Designers, Videos, Education, Software Companies
  6. Website Builder for Beginners, Bloggers, Writers, IT Companies
  7. Best Website Builder for Restaurants, Online Stores, Real Estate, Musicians
  8. Best Website Builder for podcasts and affiliate marketing
  9. Therapists and nonprofits Website Builder
  10. Portfolio and SEO Website Builder
  11. Website Builder for Kids and Musicians
  12. Website Builder for Photographers and Artists
  13. HTML Code Generator - HTML Code Creator
  14. Web Design Program - Website Design Tool
  15. Landing Page Generator - Landing Page Builder
  16. No Coding Website Builder - Website Builder For Small Business
  17. Innovative HTML Builder Drag And Drop Free for Your Next Project
  18. Is There A Completely Free QR Code Generator
  19. Extremely Comfortable Business Website Constructor Review
  20. Bootstrap Select
  21. Bootstrap Panel
  22. Bootstrap Toggle
  23. Bootstrap Modal Popup
  24. Bootstrap Row
  25. Bootstrap Multiselect
  26. Bootstrap Media queries
  27. Bootstrap Login Forms
  28. Bootstrap Layout
  29. Bootstrap Jumbotron
  30. Bootstrap Button Group
  31. Bootstrap Breakpoints
  32. Bootstrap Navbar
  33. Bootstrap Tooltip
  34. Bootstrap Textarea
  35. Bootstrap Switch
  36. Bootstrap Slider
  37. Bootstrap Progress Bar
  38. Bootstrap Label
  39. Bootstrap Header
  40. Bootstrap Clearfix
  41. Bootstrap Sidebar
  42. Bootstrap Radio
  43. Bootstrap Offset
  44. Bootstrap Menu
  45. Bootstrap Columns
  46. Bootstrap Checkbox
  47. Bootstrap Accordion
  48. Bootstrap Image
  49. Bootstrap Grid
  50. Bootstrap Form
  51. Bootstrap Glyphicons
  52. Bootstrap List
  53. Bootstrap Carousel
  54. Bootstrap Icons
  55. Bootstrap Collapse
  56. Bootstrap Popover
  57. Bootstrap Input
  58. Bootstrap Modal
  59. Bootstrap Pagination
  60. Bootstrap Button
  61. Bootstrap Alert
  62. Bootstrap Table