Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bootstrap 3 tooltip work with parent div with overflow:hidden?

Here's my code:

HTML:

<div class="cart">
   <a data-toggle="tooltip" title="add to cart">
       <i class="fa fa-cart"></i>
   </a>
</div>

JQuery:

 $('a[data-toggle="tooltip"]').tooltip({
   animated : 'fade',
   placement : 'bottom'
});

CSS:

.cart{
   overflow:hidden;
   padding:10px 3px;
}

When I hover the cart icon, the tooltip shows, but it is not at the top of the cart box.

How can I fix this?

like image 707
Peter Jack Avatar asked Oct 28 '13 09:10

Peter Jack


People also ask

What are the ways to enable Bootstrap tooltip plugin for the HTML elements?

To create a tooltip, add the data-toggle="tooltip" attribute to an element. Note: Tooltips must be initialized with jQuery: select the specified element and call the tooltip() method.

How do I change the tooltip position in bootstrap?

How to position the tooltip - auto | top | bottom | left | right. When auto is specified, it will dynamically reorient the tooltip. When a function is used to determine the placement, it is called with the tooltip DOM node as its first argument and the triggering element DOM node as its second.

Which plugin is used to create a tooltip in bootstrap?

The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.


2 Answers

You can use container attribute so tooltip itself will be placed in parent container or event body element and it won't break even with overflow hidden because it will be positioned absolutely.

$('a[data-toggle="tooltip"]').tooltip({
   animated : 'fade',
   placement : 'bottom',
   container: 'body'
});
like image 121
Vytautas Butkus Avatar answered Oct 07 '22 16:10

Vytautas Butkus


You can also simply add data-container="body" to the tooltipped element. E.g. <button type="submit" title="Add Record to Book Bag" data-toggle="tooltip" data-container="body" aria-role="button"> ... </button>

like image 36
Claas Kazzer Avatar answered Oct 07 '22 17:10

Claas Kazzer