text-overflow属性
- clip:当字数超过容器宽度时,剩余内容将被隐藏,直接从超出的位置进行裁切。
- ellipsis:当字数超过容器宽度时,剩余内容也将被隐藏,但是会显示一个省略号(…)。( 注:需要和white-space:nowrap; overflow:hidden;同时使用才能看到省略号的效果)
举例代码
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.text
{
width: 150px;
height: 20px;
border: 1px solid red;
overflow: hidden;
white-space: nowrap;
/*text-overflow: clip;*/
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="text">
这是一行文字这是一行文字这是一行文字
</div>
</body>
</html>
1.text-overflow:clip效果图
2.text-overflow:ellipsis效果图