Webkit line clamp:如何使用 webkit-line-clamp

关于Webkit line clamp的问题,在webkit line clamp中经常遇到, 我有这个代码使我的段落短

我有这个代码使我的段落短

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

但问题是,这段代码使所有内容都在一行中。我想用 3 行文本然后...我在 Google 中搜索了一下,我发现我们有一个 WebKit

webkit-line-clamp

但我不知道如何使用它,它不工作...

2

方法-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>

方法-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>
0

没有 flexbox 的解决方案

设置文本容器的高度,并相应地使用 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. enter image description here

带有 flexbox 的解决方案

您也可以从以下链接获取帮助: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>

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(145)
ҽԺplay:使用PlayCookie会话
上一篇
小程序游戏排行榜:Google Play游戏的成就和排行榜
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(40条)