最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Set Width for One Tooltip - Stack Overflow

programmeradmin0浏览0评论

I have an HTML page with a lot of links with tooltips using Bootstrap's tooltip plugin. I have found the following CSS to change the width of the tooltips:

.tooltip-inner { max-width: 350px; }

Although this works, it changes ALL of my tooltips to this width. What if I want to change just one? I tried this, but it did not work correctly:

<style rel="stylesheet" type="text/css">    
#my_tooltip .tooltip-inner { max-width: 350px; }
</style>

<a id="my_tooltip" href="#" data-toggle="tooltip" data-placement="bottom" title="tooltip content">This is a tooltip</a>

I have an HTML page with a lot of links with tooltips using Bootstrap's tooltip plugin. I have found the following CSS to change the width of the tooltips:

.tooltip-inner { max-width: 350px; }

Although this works, it changes ALL of my tooltips to this width. What if I want to change just one? I tried this, but it did not work correctly:

<style rel="stylesheet" type="text/css">    
#my_tooltip .tooltip-inner { max-width: 350px; }
</style>

<a id="my_tooltip" href="#" data-toggle="tooltip" data-placement="bottom" title="tooltip content">This is a tooltip</a>
Share Improve this question edited Jul 8, 2014 at 8:31 jgillich 76.6k7 gold badges60 silver badges88 bronze badges asked May 28, 2014 at 14:36 Tigerman55Tigerman55 2311 gold badge10 silver badges20 bronze badges 2
  • give the tooltip an extra class then amend your css for that tooltip only – Andrew Matthew Commented May 28, 2014 at 14:44
  • 1 @AndrewMatthew could you expound on that a little more? I am confused by what you mean. Maybe try making an official reply to my question. – Tigerman55 Commented May 28, 2014 at 14:48
Add a ment  | 

2 Answers 2

Reset to default 2

Probably best to do it via jquery. But css will work too:

#my_tooltip + .tooltip .tooltip-inner { width: 350px; }

and here is the js:

$(function () {
$('#my_tooltip').tooltip().on("mouseenter", function () {
    var $this = $(this),
    tooltip = $this.next(".tooltip");
    tooltip.find(".tooltip-inner").css({
        width: "350px",
    });
 });
});

The following solution worked for me

    $(yourselectorname).on('inserted.bs.tooltip', function () {
    $("body div.tooltip-inner").css("max-width", "500px");
    });
发布评论

评论列表(0)

  1. 暂无评论