css单行或者多行超出显示省略号
注意:父盒子要有宽度,不能是行内元素比如span,否则样式设置无效
单行文本过长显示省略号
.single-ellipsis{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
单行文本过长显示省略号
.many-ellipsis{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3; /*3表示超出三行隐藏 */
-webkit-box-orient: vertical;
}
案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.box{
width: 200px;
border: 1px solid deeppink;
margin: 20px;
}
.single-ellipsis{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.many-ellipsis{
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3; /*3表示超出三行隐藏 */
-webkit-box-orient: vertical;
}
</style>
</head>
<body>
<!-- 单行隐藏 -->
<div class="box single-ellipsis">111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf</div>
<!-- 多行隐藏 -->
<div class="box many-ellipsis">
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
111111111asdfsdfsdfasdfdasfasdfasdfasdfdasf
</div>
</body>
</html>
参考:CSS 文本超出隐藏