- css单行
兼容性较好
.overflow--ellipsis{
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
- css多行
兼容移动端和chrome
.overflow--ellipsis_more{
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2; /*设置省略号在容器第2行文本后*/
overflow: hidden;
}
- js多行
可使用插件解决 Clamp.js
//Single line
$clamp(myHeader, {clamp: 1});
//Multi-line
$clamp(myHeader, {clamp: 3});
//Auto-clamp based on available height
$clamp(myParagraph, {clamp: 'auto'});
//Auto-clamp based on a fixed element height
$clamp(myParagraph, {clamp: '35px'});
网友评论