Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying long text in Bootstrap tooltip

I'm trying to display a bit of long text in a twitter bootstrap tooltip. As you can see in the picture below, things aren't going smashingly. Does anyone have an easy fix for text that overflows the bootstrap tooltip?

tooltip overflow

EDIT (added requested code):

In my controller:

<a href='" + Url.Action("Index", "PP", new {id = productRow.ProductGuid, area = ""}) + "' " +            ((blTruncated) ? "class='auto-tooltip' title='" + productRow.ProductName.Replace("'", "") : "") + "'>" +             productName + "</a> 

In my view:

$('.auto-tooltip').tooltip(); 
like image 479
Jeff Borden Avatar asked Aug 29 '13 17:08

Jeff Borden


People also ask

How do I show text in tooltip?

Basic Tooltip HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .

How do I change font size in bootstrap tooltip?

You can change the variable $ tooltip-inner-font-size and assign it a new value. You will find this variable in src/mdb/scss/free/_variables. scss . Remember that this will change the text size of all tooltips.


2 Answers

I'm not quite sure about your code,
here is an example with a long tool-tip value:

Element:

 <a href="#" rel="tooltip" title="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas bibendum ac felis id commodo. Etiam mauris purus, fringilla id tempus in, mollis vel orci. Duis ultricies at erat eget iaculis.">Hover here please</a> 

Js:

$(document).ready(function () {   $("a").tooltip({     'selector': '',     'placement': 'top',     'container':'body'   }); }); 

Css:

/*Change the size here*/ div.tooltip-inner {     max-width: 350px; } 

Demo: on JsBin.com


Apprently you can only change the .tooltip-inner in Bootstrap 4, thanks @Felix Dombek

.tooltip-inner { max-width: ... } 
like image 109
funerr Avatar answered Sep 17 '22 15:09

funerr


As hinted at in the documentation, the easiest way to ensure that your tooltip does not wrap at all is to use

.tooltip-inner {     max-width: none;     white-space: nowrap; } 

With this, you don't have to worry about dimension values or anything like that. Main problem being if you have a super long line of text it will just go off of the screen (as you can see in the JSBin Example).

like image 23
cmcculloh Avatar answered Sep 20 '22 15:09

cmcculloh