要實(shí)現(xiàn)的效果

單行顯示
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
實(shí)現(xiàn)多行省略號(hào)請(qǐng)看 這里

多行省略
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
注:
- -webkit-line-clamp用來(lái)限制在一個(gè)塊元素顯示的文本的行數(shù)。 為了實(shí)現(xiàn)該效果,它需要組合其他的WebKit屬性。常見(jiàn)結(jié)合屬性:
- display: -webkit-box; 必須結(jié)合的屬性 ,將對(duì)象作為彈性伸縮盒子模型顯示 。
- -webkit-box-orient 必須結(jié)合的屬性 ,設(shè)置或檢索伸縮盒對(duì)象的子元素的排列方式 。
最后漸變背景

多行省略漸變
p{
position: relative;
line-height: 20px;
max-height: 40px;
overflow: hidden;
}
p::after{
content: "...";
position: absolute;
bottom: 0; right: 0;
padding-left: 40px;
background: -webkit-linear-gradient(left, transparent, #fff 55%);
background: -o-linear-gradient(right, transparent, #fff 55%);
background: -moz-linear-gradient(right, transparent, #fff 55%);
background: linear-gradient(to right, transparent, #fff 55%);
}
注:
- 將height設(shè)置為line-height的整數(shù)倍,防止超出的文字露出。
- 給p::after添加漸變背景可避免文字只顯示一半。