Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have tabs of matching height with bootstrap?

I'm using Bootstrap tabs to display some content. Each of my tabs is almost the same height, but not exactly so when you switch tabs, there is a slight movement of the next component.

Is it possible to make each tab panel the height of the maximum height ?

Here is an example: https://jsfiddle.net/ommnft3e/ I'd like the <hr> to not move when I switch tabs. Is that possible ?

Thanks

like image 682
Baptiste Wicht Avatar asked Jun 03 '15 11:06

Baptiste Wicht


People also ask

How do I create a navigation tab in Bootstrap?

Approach: To create a tabbed navigation menu, create a basic unordered list with list items as links. Then add classes nav and nav-tabs of bootstrap to unordered list and nav-items class to list items. Example 1: HTML.

How will you create a tabbed pills and vertical pills navigation menu in Bootstrap?

Using data attributes You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-toggle="tab" or data-toggle="pill" on an element. Use these data attributes on . nav-tabs or . nav-pills .

How do I toggle between tabs in Bootstrap?

To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a .tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class .tab-content .

What is Bootstrap tab content?

Tabs are used to separate content into different panes where each pane is viewable one at a time.


2 Answers

Override the bootstrap css and Use visibility hidden

.tab-content>.tab-pane{
    display:block;
    visibility:hidden;
}

.tab-content>.active{
    visibility:visible;
}

see the fiddle https://jsfiddle.net/devjit/ommnft3e/5/

In that case I think you will have to use javascript to determine the max height. check this fiddle .. https://jsfiddle.net/devjit/ommnft3e/8/

like image 168
Devjit Avatar answered Sep 23 '22 13:09

Devjit


I wrote this little script that manages the tab pane heights and adjust it to make them all the same height.

function tabHeightManager() {

this.margin = 0;
this.selcheck = '';
this.selmod = '';
this.running = false;

}

tabHeightManager.prototype.bind = function( _selcheck, _selmod, _margin ) {

if (typeof(_selcheck) === 'undefined')
    return false;
else
    this.selcheck = _selcheck;

if (typeof(_selmod) === 'undefined')
    return false;
else
    this.selmod = _selmod;

(typeof(_margin) === 'undefined') ? this.margin = 0 : this.margin = _margin;

var self = this;
$(window).on('resize', function() {
    setTimeout( function() { self.recalc() }, 200 );
})

self.recalc();
}

tabHeightManager.prototype.recalc = function() {
if(this.running)
    return false;

this.running = true;

var max = 0;
$(this.selcheck).each(function () {
    if (max < $(this).outerHeight(true))
        max = $(this).outerHeight(true);
});

max += this.margin;
$(this.selmod).css({'height': max});

this.running = false;
}

Just create the bootstrap tabs and after that call

    var tabMan = new tabHeightManager();
    tabMan.bind('.tab-pane','.tab-content',15);

It's quite crap but I arranged it in a hurry, hope it helps.

like image 35
Dario Corno Avatar answered Sep 20 '22 13:09

Dario Corno