How do you change the width and height of Twitter Bootstrap's tooltips?

后端 未结 21 1335
情歌与酒
情歌与酒 2020-12-12 13:26

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

相关标签:
21条回答
  • 2020-12-12 13:38

    Just override bootstrap.css

    The default value in BS2 is max-width:200px; So you can increase it with whatever fits your needs.

    .tooltip-inner {
        max-width: 350px;
        /* If max-width does not work, try using width instead */
        width: 350px; 
    }
    
    0 讨论(0)
  • 2020-12-12 13:38

    On Bootstrap 4, and if you don't want to change all tooltips width, you can use specific template for the tooltip you want :

    <a href="/link" class="btn btn-info"
       data-toggle="tooltip"
       data-placement="bottom"
       data-template="<div class='tooltip' role='tooltip'><div class='arrow'></div><div class='tooltip-inner' style='max-width: 400px;'></div></div>"
       title="This is a long message displayed on 400px width tooltip !"
    >
        My button label
    </a>
    
    0 讨论(0)
  • 2020-12-12 13:38

    With Bootstrap 4 I use

    .tooltip-inner {
        margin-left: 50%;
        max-width: 50%;
        width: 50%;
        min-width: 300px;
    }
    
    0 讨论(0)
  • 2020-12-12 13:38

    in bootstrap 3.0.3 you can do it by modifying the popover class

    .popover {
        min-width: 200px;
        max-width: 400px;
    }
    
    0 讨论(0)
  • 2020-12-12 13:41

    after some experimenting, this worked best for me:

    .tooltip-inner {
        max-width: 350px; /* set this to your maximum fitting width */
        width: inherit; /* will take up least amount of space */ 
    }
    
    0 讨论(0)
  • 2020-12-12 13:42

    Define the max-width with "important!" and use data-container="body"

    CSS file

    .tooltip-inner {
        max-width: 500px !important;
    }
    

    HTML tag

    <a data-container="body" title="Looooooooooooooooooooooooooooooooooooooong Message" href="#" class="tooltiplink" data-toggle="tooltip" data-placement="bottom" data-html="true"><i class="glyphicon glyphicon-info-sign"></i></a>
    

    JS script

    $('.tooltiplink').tooltip();
    
    0 讨论(0)
提交回复
热议问题