css text-overflow

语法:

text-overflowclip | ellipsis

取值:

clip:
不显示省略标记(...),而是简单的裁切。
ellipsis:
当对象内文本溢出时显示省略标记(...)

说明:

  1. 设置或检索是否使用一个省略标记(...)标示对象内文本的溢出。对应的脚本特性为textOverflow。
  2. text-overflow属性仅是注解,当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。要实现溢出时产生省略号的效果还须定义:强制文本在一行内显示(white-space:nowrap)及溢出内容为隐藏(overflow:hidden),只有这样才能实现溢出文本显示省略号的效果。

兼容性:

text-overflow : clip

类型IEInternet ExplorerFirefoxFirefoxChromeChromeOperaOperaSafariSafari
版本 (√)IE6 (√)Firefox 2.0 (√)Chrome 1.0.x (×)Opera 9.63 (√)Safari 3.1
(√)IE7 (√)Firefox 3.0 (√)Chrome 2.0.x (√)Safari 4
(√)IE8 (√)Firefox 3.5

text-overflow : ellipsis

类型IEInternet ExplorerFirefoxFirefoxChromeChromeOperaOperaSafariSafari
版本 (√)IE6 (×)Firefox 2.0 (√)Chrome 1.0.x (×)Opera 9.63 (√)Safari 3.1
(√)IE7 (×)Firefox 3.0 (√)Chrome 2.0.x (√)Safari 4
(√)IE8 (×)Firefox 3.5

示例:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>text-overflow</title>
6 </head>
7 <body>
8 <style type="text/css">
9 .test_demo_clip{text-overflow:clip; overflow:hidden; white-space:nowrap; width:200px; background:#ccc;}
10 .test_demo_ellipsis{text-overflow:ellipsis; overflow:hidden; white-space:nowrap; width:200px; background:#ccc;}
11 </style>
12 <h2>text-overflow : clip </h2>
13 <div class="test_demo_clip">
14 不显示省略标记,而是简单的裁切条
15 </div>
16 <h2>text-overflow : ellipsis </h2>
17 <div class="test_demo_ellipsis">
18 当对象内文本溢出时显示省略标记
19 </div>
20 </body>
21 </html>

posted on 2011-09-02 11:46  wy007  阅读(230)  评论(0编辑  收藏  举报