溢出显示时用省略号结尾。
语法:
text-overflow : clip | ellipsis
参数:
clip : 不显示省略标记(...),而是简单的裁切
ellipsis : 当对象内文本溢出时显示省略标记(...)
说明:
设置或检索是否使用一个省略标记(...)标示对象内文本的溢出。
请您注意,text-overflow:ellipsis属性在FireFox中是没有效果的。
示例:
div { text-overflow : clip; }
text-overflow是一个比较特殊的样式,我们可以用它代替我们通常所用的标题截取函数,而且这样做对搜索引擎更加友好,如:标题文件有50个汉字,而我们的列表可能只有300px的宽度。如果用标题截取函数,则标题不是完整的,如果我们用CSS样式text-overflow:ellipsis,输出的标题是完整的,只是受容器大小的局限不显示出来罢了。
text-overflow属性仅是注解,当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。
想要实现溢出时产生省略号的效果。还必须定义:强制文本在一行内显示(white-space:nowrap)及溢出内容为隐藏(overflow:hidden)。只有这样才能实现溢出文本显示省略号的效果。
我们首页建立了一个无序列表UL,里面有几个列表项LI:
一、仅定义text-overflow:ellipsis; 不能实现省略号效果。
<html>
<head>
<style type="text/css">
ul {width:300px; margin:50px auto;}
li {width:300px; line-height:25px; text-overflow:ellipsis;}
</style>
</head>
<body>
<ul>
<li>list item1</li>
<li>list item2 this item is long enough for test the effort of overflow, I think.</li>
<li>list item3</li>
</ul>
</body>
</html>
二、定义text-overflow:ellipsis; white-space:nowrap; 同样不能实现省略号效果。
<html>
<head>
<style type="text/css">
ul {width:300px; margin:50px auto;}
li {width:300px; line-height:25px; text-overflow:ellipsis; white-space:nowrap;}
a {color:#03c; font-size:13px;}
a:hover {color:#000;}
</style>
</head>
<body>
<ul>
<li>list item1</li>
<li>list item2 this item is long enough for test the effort of overflow, I think.</li>
<li>list item3</li>
</ul>
</body>
</html>
三、同时应用: text-overflow:ellipsis; white-space:nowrap; overflow:hidden; 实现了所想要得到的溢出文本显示省略号效果:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>52CSS</title>
<style type="text/css">
ul {width:300px; margin:50px auto;}
li {width:300px; line-height:25px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden;}
a {color:#03c; font-size:13px;}
a:hover {color:#000;}
</style>
</head>
<body>
<ul>
<li>list item1</li>
<li>list item2 this item is long enough for test the effort of overflow, I think.</li>
<li>list item3</li>
</ul>
</body>
</html>
http://hi.baidu.com/kychen88/blog/item/d50f85882e5301b90f2444b4.html