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

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

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

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


当前回答

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

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中测试。

其他回答

只需添加一个数据属性

data-html =“真正的”

你可以开始了。

如。用法:

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

到目前为止,它在我尝试过的大多数工具提示插件中都有效。

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

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中测试。

Use

&#013

不应该有;的性格。

这个css会帮助你。

    .tooltip {
      word-break: break-all;
    }

or if you want in one line

    .tooltip-inner {
      max-width: 100%;
    }

我的解决方案是http://jqueryui.com/tooltip/:

这里的代码(脚本中使<br/>工作的部分是"content:"):

HTML头

<head runat="server">
    <script src="../Scripts/jquery-2.0.3.min.js"></script>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <script src="../Scripts/jquery-ui-1.10.3.min.js"></script>
<script>
    /*Position:
      my =>  at
      at => element*/
    $(function () {
        $(document).tooltip({
            content: function() {
                var element = $( this );
                if ( element.is( "[title]" ) ) {
                    return element.attr( "title" );
                }

            },
            position: { my: "left bottom-3", at: "center top" } });
    });
</script>
</head>

ASPX或HTML控件

<asp:TextBox ID="Establecimiento" runat="server" Font-Size="1.3em" placeholder="Establecimiento" title="Texto 1.<br/>TIP: texto 2"></asp:TextBox>

希望这对大家有所帮助