简体   繁体   English

如何使用 webkit-line-clamp?

[英]how can I use webkit-line-clamp?

I have this code for making my paragraph short我有这段代码可以缩短我的段落

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

but the problem is that this code makes everything in one-line.但问题是这段代码使所有内容都集中在一行中。 I want to go with 3 lines of text then... I searched in the Google about it and I find out we have a WebKit for it我想用 3 行文本 go 然后......我在谷歌搜索它,我发现我们有一个 WebKit

webkit-line-clamp

but I have no idea how to use it and it doesn't work...但我不知道如何使用它并且它不起作用......

Method - 1: Using text-overflow: ellipsis;方法 - 1:使用text-overflow: ellipsis;

 span { white-space: nowrap; text-overflow: ellipsis; width: 250px; display: block; overflow: hidden }
 <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>

Method - 2: Using -webkit-line-clamp方法 - 2:使用-webkit-line-clamp

 p { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
 <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

Solution without flexbox无flexbox的解决方案

Set height of text container and use webkit-line-clamp accordingly.设置文本容器的高度并相应地使用 webkit-line-clamp。

.line-clamp-3 {
  display: block;
  display: -webkit-box;
  height: 50px;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

Text will be shown like this.文本将像这样显示。 在此处输入图像描述

Solution with flexbox使用 flexbox 的解决方案

You can also take help from this link: https://css-tricks.com/flexbox-truncated-text/您也可以从此链接获取帮助: https://css-tricks.com/flexbox-truncated-text/

 .flex-parent { display: flex; }.short-and-fixed { width: 30px; height: 30px; }.long-and-truncated { margin: 0 20px; flex: 1; min-width: 0; }.long-and-truncated span { display: inline; -webkit-line-clamp: 3; text-overflow: ellipsis; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; word-wrap: break-word; }
 <div class="flex-parent"> <div class="flex-child short-and-fixed"> </div> <div class="flex-child long-and-truncated"> <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span> </div> <div class="flex-child short-and-fixed"> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM