<div>
<p>This is a sample text.</p>
<p>This is a 2nd sample text. existing inside a paragraph. I want to make this ellipsis to avoid overflow text.</p>
<p>This is a last paragraph which is not going to display as 3 lines are already displayed</p>
</div>
必需的输出 -
This is a sample text.
This is a 2nd sample text. existing
inside a paragraph. I want to make...
我希望将div标签内的文本转换为3行省略号,同时考虑所有段落作为单个文本处理。如何实现呢?
我尝试过以下方法:
div{
width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: initial;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
<div>
<p>This is a sample text.</p>
<p>This is a 2nd sample text. existing inside a paragraph. I want to make this ellipsis to avoid overflow text.</p>
<p>This is a last paragraph which is not going to display as 3 lines are already displayed</p>
</div>
如果div内部有多个段落,它的功能可能无法正常工作。