bootstrap "tooltip" and "popover" add extra size in table bootstrap "tooltip" and "popover" add extra size in table javascript javascript

bootstrap "tooltip" and "popover" add extra size in table


Note: Solution for Bootstrap 3.3+

Simple Solution

In the .tooltip() call, set the container option to body:

$(function () {  $('[data-toggle="tooltip"]').tooltip({    container : 'body'  });});

Alternatively you can do the same by using the data-container attribute:

<p data-toggle="tooltip" data-placement="left" data-container="body" title="hi">some text</p>

Why does this work?

This solves the problem because by default, the tooltip has display: block and the element is inserted in the place it was called from. Due to the display: block, it affects the page flow in some cases, i.e pushing other elements down.

By setting the container to the body element, the tooltip is appended to the body instead of where it was called from, so it doesn't affect other elements because there is nothing to "push down".


Note: Solution for Bootstrap 3.0 ~ 3.2

You need to create an element inside a td and apply a tooltip to it, like this, because a tooltip itself is a div, and when it is placed after a td element it brakes table layout.

This problem was introduced with the latest release of Bootstrap. There are ongoing discussions about fixes on GitHub here. Hopefully the next version includes the fixed files.


Note: Solution for Bootstrap 3.3+

If you want to avoid to break the table when applying a tooltip to a <td> element, you could use the following code:

    $(function () {        $("body").tooltip({            selector: '[data-toggle="tooltip"]',            container: 'body'        });    })

You html could look like this:

<td data-toggle="tooltip" title="Your tooltip data">    Table Cell Content</td>

This even works with dynamically loaded content. For example in use with datatables