一、单行文字溢出省略效果
正常300px宽度的段落
文字溢出隐藏效果
关键CSS
{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
测试代码:
<!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>
.text_box {
width: 300px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
</head>
<body>
<p class="text_box">Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae rem consectetur earum repellendus qui, ab
eligendi ipsam quos accusamus architecto! Pariatur doloribus consequatur doloremque, facilis inventore sequi
dolore eius eum.</p>
</body>
</html>
二、多行文字溢出省略效果
仅支持对-webkit-私有前缀支持良好的浏览器
文字溢出隐藏效果
关键CSS
{
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
测试代码:
<!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>
.text_box {
width: 300px;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
</style>
</head>
<body>
<p class="text_box">Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae rem consectetur earum repellendus qui, ab
eligendi ipsam quos accusamus architecto! Pariatur doloribus consequatur doloremque, facilis inventore sequi
dolore eius eum.</p>
</body>
</html>