【问题标题】:Pure CSS Ellipsis For Three or More Lines of Text三行或更多行文本的纯 CSS 省略号
【发布时间】:2014-10-16 09:30:14
【问题描述】:

是否有一种纯 CSS 方式(无 JavaScript/jQuery)只显示前两行,如果有三行或更多行,隐藏多余的行并显示省略号?

例如,我该如何拿这个小提琴:

http://jsfiddle.net/0yyr3e63/

...让它看起来像这样?

Lorem Ipsum Dolor
Sit Amet Consectetur

Ut Enim Ad Minim
Veniam Quis Nostrud...

Duis Aute Irure
Dolor In...

提前致谢。

【问题讨论】:

标签: html css overflow ellipsis


【解决方案1】:

您可以将text-overflow:ellipsis 属性与height 一起使用。

这样

.truncate 
{
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
height:100px;
}

通过使用 text-overflow,您可以在不使用 javascript 的情况下显示输出。

来源

Source Link

To Learn more about truncating. Read this link

新更新

对于多行省略号,您可以使用此方法。

css
.classname:after{
content: "\02026";
} 

Multiline-Ellipsis

我认为可能有用的几个链接

1.Codepen example

2.Css Tricks

【讨论】:

  • 我认为 OP 知道text-overflow: ellipsis; 但他正在寻找实现多行省略号的解决方案。
  • 他的小提琴表明他没有使用省略号属性@HashemQolami
  • text-overflow: ellipsis 仅适用于单行截断。我只需要显示前两行,如果存在其他行,则后跟省略号(请参阅我在 OP 中的示例)。
  • 你是对的,但是text-overflow: ellipsis; 不适用于多行文本。
  • @Ryan 你可能想知道"OP" stands for "Original Poster" 不是帖子本身:)
猜你喜欢
  • 1970-01-01
  • 2012-03-20
  • 2017-03-14
  • 2012-06-09
  • 2014-11-18
  • 2016-12-22
  • 1970-01-01
  • 2021-05-01
  • 2011-07-13
相关资源
最近更新 更多