Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap tooltip data-container=body and limit scope of css on .tooltip-inner

I am using bootstrap 3.3 tooltips and had an issue with the tooltips being cropped/hidden. I solved this by setting data-container="body".

<!--...-->
<span class="callOutImg">
  <a href="#" data-toggle="tooltip" data-container="body" data-placement="top" class="optionTooltip" title="Hello my name is Inigo Montoya">
    <img src='/images/info-bubble-big.png' />
  </a>
</span>
<!--...-->

Using these effects all of my tooltips - which is not what I want.

However, I want to set a specific style on the .tooltip-inner only for a subset of tooltips on the page. These tooltips are now however contained in body so the scope is more or less global.

I can only access .tooltip-inner for these using:

body .tooltip-inner {
  background-color: #40a0d0;
}

or

.tooltip-inner {
  background-color: #40a0d0;
}

How do I set a different data-container? (I have tried classes and id's) Or can anyone suggest a way to limit the scope of .tooltip-inner selection?

like image 950
Jason Avatar asked Jan 14 '15 23:01

Jason


People also ask

What is Bootstrap tooltip?

Bootstrap Tooltip displays informative text when users hover, focus, or tap an element. They display text tips next to the element in question. Documentation and examples for adding custom tooltips with CSS and JavaScript using CSS3 for animations and data-mdb-attributes for local title storage.

What is the tooltip component?

The Tooltip component is small pop-up box that appears when the user moves the mouse pointer over an element: To create a tooltip, add the data-toggle="tooltip" attribute to an element.

How to display text inside a tooltip using jQuery?

Use the title attribute to specify the text that should be displayed inside the tooltip: Note: Tooltips must be initialized with jQuery: select the specified element and call the tooltip () method.

How do I add a tooltip to an element?

To create a tooltip, add the data-toggle="tooltip" attribute to an element. Use the title attribute to specify the text that should be displayed inside the tooltip:


1 Answers

There is a way to add a css class to a tooltip based on which element it is attached to, even if you have set data-container="body" on the element.

$('.element1')
    .tooltip()
    .each(function() {
        $(this).data('bs.tooltip').tip().addClass('tooltip-class1');
    });

See a working example here

like image 152
Ferrard Avatar answered Sep 28 '22 03:09

Ferrard