gpt4 book ai didi

html - 如何用长文本填充DIV并在溢出时显示省略号

转载 作者:行者123 更新时间:2023-11-28 17:29:53 24 4
gpt4 key购买 nike

我有以下 JSFiddle:http://jsfiddle.net/ofrj55j4/21/

如何在显示省略号之前在 DIV 中显示尽可能多的文本(现在它只显示一行)?

HTML:

<div class="col span_1_of_3" style="height: 120px;">
<div class="test2n" style="height: 100%;">
<div class="main">
<img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="http://i59.tinypic.com/23hvrc2.png" />
</div>
<div class="sub">
<div class="sl"><a href="/template.aspx?id=2790">How we can better develop</a></div>
<div class="sr">This DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>



<div class="col span_1_of_3" style="height: 120px;">
<div class="test2n" style="height: 100%;">
<div class="main">
<img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="http://i59.tinypic.com/23hvrc2.png" />
</div>
<div class="sub">
<div class="sl"><a href="/template.aspx?id=2790">How we can better develop</a></div>
<div class="sr">This DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>



<div class="col span_1_of_3" style="height: 120px;">
<div class="test2n" style="height: 100%;">
<div class="main">
<img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="http://i59.tinypic.com/23hvrc2.png" />
</div>
<div class="sub">
<div class="sl"><a href="/template.aspx?id=2790">How we can better develop</a></div>
<div class="sr">This DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>

最佳答案

目前还没有令人满意的纯 CSS 解决方案。这个 CSS 在某些情况下可以工作:

display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;

有一些 JS 解决方案可能更有趣,例如Clamp.js

这是一个很好的article关于不同的方法和带有 examples 的 CodePen

关于html - 如何用长文本填充DIV并在溢出时显示省略号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26344520/

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