How to make Twitter Bootstrap tooltips have multiple lines?

后端 未结 6 1117
南笙
南笙 2020-12-07 13:06

I am currently using the below function to create text that will be displayed using Bootstrap’s tooltip plugin. How come multiline tooltips only work with

相关标签:
6条回答
  • 2020-12-07 13:13

    If you're using Twitter Bootstrap Tooltip on non-link element, you can specify, that you want a multi-line tooltip directly in HTML code, without Javascript, using just the data parameter:

    <span rel="tooltip" data-html="true" data-original-title="1<br />2<br />3">5</span>
    

    This is just an alternative version of costales' answer. All the glory goes to him! :]

    0 讨论(0)
  • 2020-12-07 13:14

    You can use the html property: http://jsfiddle.net/UBr6c/

    My <a href="#" title="This is a<br />test...<br />or not" class="my_tooltip">Tooltip</a> test.

    $('.my_tooltip').tooltip({html: true})
    
    0 讨论(0)
  • 2020-12-07 13:25

    In Angular UI Bootstrap 0.13.X, tooltip-html-unsafe has been deprecated. You should now use tooltip-html and $sce.trustAsHtml() to accomplish a tooltip with html.

    https://github.com/angular-ui/bootstrap/commit/e31fcf0fcb06580064d1e6375dbedb69f1c95f25

    <a href="#" tooltip-html="htmlTooltip">Check me out!</a>
    
    $scope.htmlTooltip = $sce.trustAsHtml('I\'ve been made <b>bold</b>!');
    
    0 讨论(0)
  • 2020-12-07 13:25

    The CSS solution for Angular Bootstrap is

    ::ng-deep .tooltip-inner {
      white-space: pre-wrap;
    }
    

    No need to use a parent element or class selector if you don't need to restrict it's use. Copy/Pasta, and this rule will apply to all sub-components

    0 讨论(0)
  • 2020-12-07 13:27

    You can use white-space:pre-wrap on the tooltip. This will make the tooltip respect new lines. Lines will still wrap if they are longer than the default max-width of the container.

    .tooltip-inner {
        white-space:pre-wrap;
    }
    

    http://jsfiddle.net/chad/TSZSL/52/

    If you want to prevent text from wrapping, do the following instead.

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

    http://jsfiddle.net/chad/TSZSL/53/

    Neither of these will work with a \n in the html, they must actually be actual newlines. Alternatively, you can use encoded newlines &#013;, but that's probably even less desirable than using <br>'s.

    0 讨论(0)
  • 2020-12-07 13:39

    If you are using Angular UI Bootstrap, you can use tooltip with html syntax: tooltip-html-unsafe

    e.g. update to angular 1.2.10 & angular-ui-bootstrap 0.11: http://jsfiddle.net/aX2vR/1/

    old one: http://jsfiddle.net/8LMwz/1/

    0 讨论(0)
提交回复
热议问题