单行文本显示省略号
text-overflow: ellipsis /* 显示省略号 */
1.文本盒子要有固定的宽高大小
2.文本必须要强制性的在一行显示 white-space:nowrap;
3.超出去的文本需要隐藏起来overflow:hidden;
4.隐藏文本需要变成省略号text-overflow:ellipsis;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width: 300px;
height: 400px;
border: 1px solid #000;
margin: 100px auto;
}
p{
width: 300px;
height: 30px;
/* background: pink; */
white-space: nowrap; /* 强制性的在一行显示 */
overflow: hidden;
text-overflow: ellipsis /* 显示省略号 */;
line-height: 30px;
}
</style>
</head>
<body>
<div>
<img src="https://img12.360buyimg.com/seckillcms/s140x140_jfs/t1/201156/2/15784/81512/61935149E6926b30a/24a3ddcdde73482a.jpg.webp" alt="">
<p>这是一个手机这是一个手机这是一个手机这是一个手机</p>
</div>
</body>
</html>