纯CSS实现单/多行文本省略

1
2
3
4
5
6
<div class="content">
<h3>This Is Title</h3>
<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>
</div>

webkit内核的实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.content {
background: #C87878;
border: 1px solid #fff;
box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.18);
margin:0 auto;
width: 20%;
height: 100%;
padding: 10px;
}

h3 {
text-align: center;
}

p {
text-overflow: ellipsis; /*表示超出盒子的部分使用省略号表示*/
overflow: hidden;
display: -webkit-box; /*设置块元素的布局为伸缩布局*/
-webkit-line-clamp: 6; /*设置块元素包含的文本行数*/
-webkit-box-orient: vertical;
}
0%