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

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

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

我试过更换?:

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

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


当前回答

可以手动创建更漂亮的工具提示,并可以包含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的帖子。在这里试验一下上面的代码。

其他回答

从Firefox 12开始,他们现在支持使用换行HTML实体的换行:&#10;

<span title="First line&#10;Second line">Test</span>

这在IE中工作,并且根据HTML5的title属性规范是正确的。

我使用的是火狐68.7.0 ESR和&#013;是行不通的。通过<CR>断行确实有用,所以我使用它,因为它简单而向前。

也就是说,

<option title="Constraint PSC/SCS/Activity
Definition Constraint Checker
Database Start Notifier">CnCk

至于谁&#10;没有工作,你必须样式的元素上的行可见如下:

它引用自GuitarWorker对在工具提示中添加换行符的回答。

使用data-html="true"并应用<br>。

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

它们都适用……