【发布时间】:2015-06-28 03:28:25
【问题描述】:
我正在使用一些代码,当您将鼠标悬停在某些文本上时会显示一个文本框。问题是文本框中显示的文本来自它所在的<a> 标记的属性,我无法对其进行格式化。我想在文本框中做一个列表,但我只能让它只是一堵文字墙。
HTML:
<a data-text="Could use this text instead of title" title="1. ~~~~ List item (/br)~~~~
2. ~~~~ List item ~~~~
3. ~~~~ List item ~~~~
4. ~~~~ List item ~~~~
5. ~~~~ List item ~~~~ " class="tooltip">Hover over this text</a>
CSS:
.tooltip{
display: inline;
position: relative;
}
.tooltip:hover:after{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 100%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
}
content: attr(title);
.tooltip:hover:before{
border: solid;
border-color: #333 transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
查看此演示:http://jsfiddle.net/h3tqwust/1/
如何为此设置文本格式(有换行符)?
【问题讨论】:
-
你能给我们创建一个demo吗?
-
@divy3993 我添加了一个演示
-
是的,我看到了,就你所需要的而言,@Marc Audet 有正确的答案。
-
如果您仍然需要使用 JS/JQuery 的完全响应式工具提示,并且任何格式都没有问题,请随时询问。