On the Masonry website, we read that Masonry is …
Bootstrap is one of the most widely adopted, open-source, front-end frameworks. Include Bootstrap in your project, and you’ll be able to whip up responsive web pages in no time.
I did, and this article highlights what the issue is and what you can do to solve it.
Bootstrap Tabs Explained
Bootstrap’s Tabs component includes two key, related pieces: a tabbed navigation element and a number of content panels. On page load, the first panel has the class
.active is present the panel is visible, otherwise the panel is hidden.
If you have some web content that’s best presented in individual chunks, rather than crammed all in one spot, this kind of tabs component might come in handy.
In some cases, the content inside each panel is suited to being displayed in a responsive grid layout. For instance, a range of products, services, and portfolio items are types of content that can be displayed in grid format.
However, if grid cells are not of the same height, something like what you see below can happen.
A wide gap separates the two rows of content and the layout appears broken.
Nowadays, Bootstrap solves the equal-width issue with the brand new card component, which is based on Flexbox. Just adding the
card-deck class to a group of card components is sufficient to achieve equal-width columns.
Setting Up a Demo Page
Getting a demo page up and running helps to show how integrating Bootstrap’s Tabs with Masonry is not as straightforward as one might expect.
This article’s demo page is based on the starter template, available on the Bootstrap website.
Below is the skeleton of the markup for the tabs component:
nav nav-tabs classes are responsible for giving the tabs their characteristic appearance. The value of the
href attribute forms the relationship between a single tab and its corresponding tabbed content. For instance, an
href value of
#home creates a relationship with the tabbed content with
id="home": clicking that particular tab reveals the contents inside the
div with the
id value of
Also, notice how Bootstrap pays attention to accessibility attributes like
Here’s a code snippet to illustrate the tabbed content’s structure:
Tab 1 Content
Card text here.
Last updated 3 mins ago
Just add a similar structure for each tabbed content section corresponding to the tabs elements you coded above.
For the full code, check out the CodePen demo.
Continue reading %Getting Bootstrap Tabs to Play Nice with Masonry%