---
title: "CSS3 text-overflow 文本溢出"
author: "小丑鱼0703"
date: "2015-01-20T10:08:23Z"
tags: []
categories: ["Web前端"]
slug: "css3-text-overflow"
draft: false
lastmod: "2015-03-30T10:30:05Z"
id: 2177536
url: "https://wangjingyi.iteye.com/blog/2177536"
---

text-overflow 属性规定当文本溢出包含元素时发生的事情。
语法：text-overflow: clip|ellipsis|string;
clip         修剪文本。	
ellipsis     显示省略符号来代表被修剪的文本。

注意：text-overflow：ellipsis;要与white-space:nowrap; 和overflow:hidden; 一起使用才有效果。因为text-overflow只是用来说明**文字溢出时用什么方式显示**，要实现溢出时产生省略号的效果，还须定义**强制文本在一行内显示**（white-space:nowrap）及**溢出内容为隐藏**（overflow:hidden），只有这样才能实现溢出文本显示省略号的效果


```html
<div class="test" >This is some long text that will not fit in the box</div>
```



```html

div.test{
white-space:nowrap;
overflow:hidden;  
text-overflow:clip;
width:12em; 
border:1px solid #000000;
}

```

效果：![](http://dl2.iteye.com/upload/attachment/0105/4136/93db03df-2cb2-3b15-96b6-e199ce39a168.png)

```html

div.test{
white-space:nowrap;
overflow:hidden;  
text-overflow:ellipsis;
width:12em; 
border:1px solid #000000;
}

```

效果：![](http://dl2.iteye.com/upload/attachment/0105/4138/5e36a1ed-8b9e-39ca-b17e-23a2c27779af.png)