我目前正在为我们的网站添加冗长的工具提示,我想(不必求助于一个神奇的jQuery插件,我知道有很多!)使用回车来格式化工具提示。

为了添加提示,我使用了title属性。我环顾了一下常用的网站,并使用了基本的模板:

<a title='Tool?Tip?On?New?Line'>link with tip</a>

我试过更换?:

< br / > &013;/ & # 13; \ r \ n 环境。换行符(我使用c#)

以上方法都行不通。这可能吗?


当前回答

在寻找在引导工具提示中显示断线的解决方案时,我被引导到此页面。当data-toggle="tooltip"被添加到HTML标签中时,引导工具提示将显示出来。

最后,我发现一个data-html="true"应该被添加到标签中,这样做你的标题内的HTML将被呈现。然后使用<br>来breakline。检查下面的示例:

之前(未显示任何折线):

<i class="bi bi-x-circle" data-toggle="tooltip" data-placement="top" title="test1 <br> test2"></i>

After(显示折线):

<i class="bi bi-x-circle" data-toggle="tooltip" data-html="true" data-placement="top" title="test1 <br> test2"></i>

- Laravel和Blade程序员的提示:你可以用nl2br("string")函数将\n转换为<br>。

-以上解决方案已在谷歌Chrome 98中测试。

其他回答

& # 13;可在所有主流浏览器(包括IE)上运行

如果你试图在一个React项目中这样做,你将以下面的格式呈现:

title={`First line of text ${varOne} &#13; Second line of text ${varTwo} &#13; Third line of text ${varThree}`}

那么&#13;,&#10;类似的解决方案并不奏效。它们实际上会呈现为文本。

相反,根据需要实际创建文本是更好的选择。为了更好地理解,举个例子:

title={`First line of text ${varOne}
Second line of text ${varTwo}
Third line of text ${varThree}`}

确保在“第二行文本”和“第三行文本”之前删除制表符/空格缩进。否则他们也会渲染。

它在谷歌Chrome 96和Firefox 95.0b12(开发者版,因为,为什么不呢)上进行了测试。它应该也适用于大多数现代浏览器。

在Chrome 16或更早的版本中,你可以使用“\n”。顺便说一句,“\t”也可以。

可以手动创建更漂亮的工具提示,并可以包含HTML格式。

<!DOCTYPE html>
<html>
<style>
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #555 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
</style>
<body style="text-align:center;">

<h2>Tooltip</h2>
<p>Move the mouse <a href="#" title="some text
more&#13;&#10;and then some">over</a> the text below:</p>

<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text
some <b>more</b><br/>
<i>and</i> more</span>
</div>

<div class="tooltip">Each tooltip is independent
<span class="tooltiptext">Other tooltip text
some more<br/>
and more</span>
</div>

</body>
</html>

这是来自W3Schools的帖子。在这里试验一下上面的代码。

在IE, Chrome, Safari, Firefox(最新版本2012-11-27)中测试: & # 13;

它们都适用……