單行文本的溢出顯示省略號
p {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
}
多行文本的溢出顯示省略號
方法一:
p {display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;text-overflow: ellipsis;
}
適用范圍:
因使用了WebKit的CSS擴展屬性,該方法適用于WebKit瀏覽器及移動端;不兼容IE瀏覽器。
方法二:
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瀏覽器上出現文字超過就省略的效果,但是不出現…省略號!