用到三个属性
white-space: nowrap; /*在一行显示*/
overflow: hidden; /*当前盒子的宽度超出部分隐藏*/
text-overflow: ellipsis; /*超出部分用省略号代替*/
<!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;
height: 100px;
background-color: #ccc;
white-space: nowrap; /*在一行显示*/
overflow: hidden; /*当前盒子的宽度超出部分隐藏*/
text-overflow: ellipsis; /*超出部分用省略号代替*/
}
</style>
</head>
<body>
<div>
6666666666666666666666666666666666666666666666
</div>
</body>
</html>
运行前
运行后