gpt4 book ai didi

html - 如何制作包含多个段落的div省略号?

转载 作者:行者123 更新时间:2023-12-04 12:35:24 25 4
gpt4 key购买 nike

<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 中有多个段落,它就不能按预期正常工作。

最佳答案

考虑 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>

关于html - 如何制作包含多个段落的div省略号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62326049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com