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