elipsis 多行情况出现点点点 很实用 ,虽然只能支持chome -webkit-line-clamp: 2;-webkit-box-orient: vertical;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.container{
width:200px;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
word-break: break-all;
}
</style>
</head>
<body>
<div class="container">
你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好
</div>
</body>
</html>
兼容其它浏览器 使用js代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
#container {
height: 50px;
line-height: 25px;
overflow: hidden;
width:100px;
border:1px solid black;
}
#text{
margin:0px;
padding:0px;
}
</style>
</head>
<body>
<div id="container">
<p id="text">
你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好</p>
</div>
<script>
var divH = document.getElementById("container").clientHeight;
var p = document.getElementById("text");
while (p.clientHeight > divH) {
p.innerText = p.innerText.replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "...");
};
</script>
</body>
</html>
参考文档:http://c7sky.com/text-overflow-ellipsis-on-multiline-text.html