I created a tooltip using Twitter Bootstrap.
The tooltip is displaying with three lines. However, I would like to display the tooltip with only one line.
How do I change the width of the tooltip? Is this specific to Twitter Bootstrap or to tooltips themselves?
I had the same problem, however all popular answers - to change
.tooltip-inner{width}
for my task failed to do the job right. As for other (i.e. shorter) tooltips fixed width was too big. I was lazy to write separate html templates/classes for zilions of tooltips, so I just replaced all spaces between words with
in each text line.Just override bootstrap.css
The default value in BS2 is max-width:200px; So you can increase it with whatever fits your needs.
Just override the default
max-width
to whatever fits your needs.When max-width doesn't work (option 1)
If max-width does not work, you could use a set width instead. This is fine, but your tooltips will no longer resize to fit the text. If you don't like that, skip to option 2.
Correctly dealing with small containers (option 2)
Since Bootstrap appends the tooltip as a sibling of the target, it is constrained by the containing element. If the containing element is smaller than your
max-width
, thenmax-width
won't work.So, when
max-width
doesn't work, you just need to change thecontainer
:Pro Tip: the container can be any selector, which is nice when you only want to override styles on a few tooltips.
On BS3
I realize this is a very old question, but if I landed here, so will others. So I figured I weigh in.
If you want the tooltip to be responsive to one line only regardless of how much content you add to it, the width has to be flexible. However, Bootstrap does initiate the tooltip to a width, so you have to at least declare what that width will be and make it flexible from that size on up. This is what I recommend:
The
min-width
declares a starting size. As opposed to the max-width, as some other would suggest, which it declares a stopping width. According to your question, you shouldn't declare a final width or your tooltip content will eventually wrap at that point. Instead, you use an infinite width or flexible width.max-width: 100%;
will ensure that once the tooltip has initiated at 100px wide, it will grow and adjust to your content regardless of the amount of content you have in it.KEEP IN MIND Tooltips are not intended to carry a lot of content. It could look funky if you had a long string across the entire screen. And it will definitely will have an impact in your responsive views, specially smartphone (320px width).
I would recommend two solutions to perfect this:
data-placement:right
, your tooltip content will not be visible in smartphones (hence why bootstrap initially designed them to be responsive to its content and allow it to wrap)@media
query to reset your tooltip to fit the smartphone view. Like this:My demo HERE demonstrates the flexibility and responsiveness on the tooltips according to content size and device display size as well
Define the max-width with "important!" and use data-container="body"
CSS file
HTML tag
JS script