Add line break within tooltips

后端 未结 27 2304
北恋
北恋 2020-11-28 02:23

How can line breaks be added within a HTML tooltip?

I tried using
and \\n within the tooltip as follows:



        
相关标签:
27条回答
  • 2020-11-28 02:50

    Just use the entity code 
 for a linebreak in a title attribute.

    0 讨论(0)
  • 2020-11-28 02:52

    Just add a data attribute

    data-html="true"

    and you're good to go.

    Eg. usage:

    <i data-html="true" class="tooltip ficon-help-icon" twipsy-content-set="true" data-original-title= "<b>Hello</b> Stackoverflow" </i>
    

    It has worked in majority of the tooltip plugins i have tried as of now.

    0 讨论(0)
  • 2020-11-28 02:52

    So if you are using bootstrap4 then this will work.

    <style>
       .tooltip-inner {
        white-space: pre-wrap;
       }
    
    </style>
    
    <script> 
        $(function () {
          $('[data-toggle="tooltip"]').tooltip()
        })
    </script>
    
    <a data-toggle="tooltip" data-placement="auto" title=" first line &#010; next line" href= ""> Hover me </a>
    

    If you are using in Django project then we can also display dynamic data in tooltips like:

    <a class="black-text pb-2 pt-1" data-toggle="tooltip" data-placement="auto"  title="{{ post.location }} &#010; {{ post.updated_on }}" href= "{% url 'blog:get_user_profile' post.author.id %}">{{ post.author }}</a>
    
    0 讨论(0)
  • 2020-11-28 02:54

    The &#013; combined with the style white-space: pre-line; worked for me.

    0 讨论(0)
  • 2020-11-28 02:54

    I found it. It can be done by simply doing like this

    <a ref="#" title="First Line
                      Second Line
                      Third line">Hover Me</a>
    
    0 讨论(0)
  • 2020-11-28 02:55
    \n
    

    with the styling

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

    worked for me.

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