如何在HTML工具提示中添加换行符?

我尝试在工具提示中使用<br/>和\n,如下所示:

<a href="#" title="Some long text <br/> Second line text \n Third line text">Hover me</a>

然而,这是无用的,我可以在工具提示中看到文字<br/>和\n。任何建议都会很有帮助。


当前回答

只需添加data-html="true"

<a href="#" title="Some long text <br/> Second line text \n Third line text" data-html="true">Hover me</a>

其他回答

只需使用实体代码&#013;用于标题属性中的换行符。

对我来说,两步解决方案(结合格式化标题和添加样式)是有效的,如下所示:

1) title属性的格式:

<a ref="#" title="First Line
                  Second Line
                  Third line">Hover Me</a>

2)在tips元素中添加如下样式:

white-space: pre-line;

在IE8、Firefox 22和Safari 5.1.7中测试。

只需使用实体代码&#xA;用于标题属性中的换行符。

<a title="First Line &#xA;Second Line">Hover Me </a>

只需添加data-html="true"

<a href="#" title="Some long text <br/> Second line text \n Third line text" data-html="true">Hover me</a>

如果你用的是bootstrap4,那么这个是可行的。

<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>

如果你在Django项目中使用,那么我们也可以在工具提示中显示动态数据,比如:

<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>