CSS隐藏文本溢出并用省略号代替
程序员文章站
2022-04-22 14:02:06
...
<!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>
div {
width: 100px;
border: 1px solid grey;
}
span {
/* 单行文本溢出隐藏 */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
}
</style>
</head>
<body>
<div><span>单行文本换行和多行文本换行</span></div>
</body>
</html>
<!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>
div {
width: 100px;
border: 1px solid grey;
}
span {
/* 多行文本溢出隐藏 */
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;/*显示行数*/
}
</style>
</head>
<body>
<div><span>单行文本换行和多行文本换行</span></div>
</body>
</html>
上一篇: 兼容ie的文字超出显示省略号