1 2 3 4 5 |
p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
方法一:
1 2 3 4 5 6 7 |
p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; text-overflow: ellipsis; } |
适用范围:
因使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;不兼容IE浏览器。
方法二:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
p { position:relative; line-height:20px; height:60px; overflow:hidden; } p::after { content:"..."; position:absolute; bottom:0; right:0; padding-left:45px; 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%); } |
局限性:
该方法能在谷歌和IE浏览器上出现文字超过就省略的效果,但是不出现…省略号!