我正在尝试对一段文本应用省略号(ellipsis),但是它会截取所有段落的第一行。然而,我只想显示内容的第一行。
示例内容:
通过websocket发送消息时会触发这段代码。然而,+ msg +
并不能识别消息中的换行符(line breaks)。每一句话都显示在同一行中。
优化这段jQuery代码,使+ msg +
能够检测到换行。
目前我得到的结果如图所示:
而我真正想要的效果是:
这是我的CSS样式代码:
.content .message {
font-size: 0.8rem;
color: #afb9d7;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
HTML结构如下:
<div class="content">
<div class="name">Shreyansh Jha </div>
<div class="message" data-msg="While sending message via websocket this code is triggered. However, '+ msg +' does not detect new lines (line breaks) in the message. Every sentence appears in the same line.
Optimize this jquery code so that '+ msg +' can detect new lines.">
While sending message via websocket this code is triggered. However, '+ msg +' does not detect new lines (line breaks) in the message. Every sentence appears in the same line.
<br>
<br>
Optimize this jquery code so that '+ msg +' can detect new lines.
</div>
</div>
如何实现输出的结果呢?