轉自:http://www.daqianduan.com/6179.html 感謝做者html
一、單行文本的溢出顯示省略號web
overflow: hidden; text-overflow:ellipsis; white-space: nowrap;
二、多行文本溢出顯示省略號瀏覽器
(1)方法一:因使用了WebKit的CSS擴展屬性,該方法適用於WebKit瀏覽器及移動端優化
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
(2)方法二:該方法適用範圍廣,但文字未超出行的狀況下也會出現省略號,可結合js優化該方法。spa
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%); }
注意:code