1.给定盒子宽度后,在css加上以下样式就可以啦(单行)
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-break: break-all;
2.给定盒子宽度后,在css加上以下样式就可以啦(多行)
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 2;//2表示行数,看自己需求设置超出多少行后出现...
-webkit-box-orient: vertical;
案例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
div {
width: 100px;
background-color: pink;
}
.ellipsis-2 {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
</style>
</head>
<body>
<div class="ellipsis-2">所得税靠的就是肯定会萨克雷查看了靠的就是肯德基</div>
</body>
</html>