1.單行文本超出省略號顯示:
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
2.多行文本超出省略號顯示:
(1)這種方法不兼容眠砾,只適合webkit內(nèi)核的瀏覽器和移動端
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;(文本的行數(shù))
-webkit-box-orient: vertical;
(2)兼容寫法
p {
? ? position:relative;
? ? line-height:1.6em;
? ? height:3.2em;(n行、n倍的行高)
? ? overflow:hidden;
}
p::after {
? ? content:"...";
? ? position:absolute;
? ? bottom:0;
? ? right:0;
? ? padding:0 10px;
? ? background:url(bg.png) repeat-y;
}
height高度真好是line-height的2倍;
結(jié)束的省略號用了半透明的png做減淡的效果鲸阔,或者設(shè)置背景顏色佃声;
IE6-7不顯示content內(nèi)容灸姊,所以要兼容IE6-7可以是在內(nèi)容中加入一個標(biāo)簽,比如用...去模擬秉溉;
要支持IE8力惯,需要將::after替換成:after;