如何使 div 里面有多个段落的省略号?
How to make div ellipsis with multiple paragraphs inside it?
<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>
required output -
This is a sample text.
This is a 2nd sample text. existing
inside a paragraph. I want to make...
我想通过将所有段落视为一个文本来在 div 省略号内创建 3 行文本。
我怎样才能做到这一点??
I have tried following one -
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。
对多行
使用clamp
fiddle 玩转。
.MainDiv {
border: 1px solid black;
width: 200px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.MainDiv p {
overflow: hidden;
}
<div class="MainDiv">
<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>
</div>
你可以为单行
做这样的事情
.MainDiv {
border: 1px solid black;
width: 200px;
}
p {
text-overflow: ellipsis;
overflow: hidden;
width: 200px;
white-space: nowrap;
}
<div class="MainDiv">
<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>
</div>
考虑display:contents;
p个元素结合一个伪元素技巧来保持p
之间的分离
div {
width: 400px;
overflow: hidden;
text-overflow: ellipsis;
white-space: initial;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
div p {
display: contents;
}
p:after {
content: "\A";
white-space:pre;
}
<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>
<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>
required output -
This is a sample text.
This is a 2nd sample text. existing
inside a paragraph. I want to make...
我想通过将所有段落视为一个文本来在 div 省略号内创建 3 行文本。
我怎样才能做到这一点??
I have tried following one -
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。
对多行
使用clamp
fiddle 玩转。
.MainDiv {
border: 1px solid black;
width: 200px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.MainDiv p {
overflow: hidden;
}
<div class="MainDiv">
<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>
</div>
你可以为单行
做这样的事情.MainDiv {
border: 1px solid black;
width: 200px;
}
p {
text-overflow: ellipsis;
overflow: hidden;
width: 200px;
white-space: nowrap;
}
<div class="MainDiv">
<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>
</div>
考虑display:contents;
p个元素结合一个伪元素技巧来保持p
div {
width: 400px;
overflow: hidden;
text-overflow: ellipsis;
white-space: initial;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
div p {
display: contents;
}
p:after {
content: "\A";
white-space:pre;
}
<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>