<html>
<head>
<style type="text/css">
ul li {
float: left;
overflow: hidden;
font-size: 12px;
margin-right: 10px;
text-indent: 0px;
}
ul li {
font-size: 12px;
width: 80px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
word-break: keep-all;
}
</style>
</head>
<body><div>
<ul>
<li>fsdfsldfsdfsdf</li>
<li>fsdfsldfsdfsdf</li>
<li>fsdfsldfsdfsdf</li>
<li>瑁卡拉我中是国人民工膛 顶替</li>
</ul>
</div>
使用text-overflow:ellipsis对溢出文本显示省略号有两个好处,一是不用通过程序限定字数;二是有利于SEO。需要使用对对溢出文本显示省略号的通常是文章标题列表,这样处理对搜索引擎更友好,因为标题实际上并未被截字,而是局限于宽度而未被显示而已。
通常的做法是这样的:
1.overflow:hidden;
2.text-overflow:ellipsis;
3.-o-text-overflow:ellipsis;
4.white-space:nowrap;
5.width:100%;
其中,overflow: hidden和white-space: nowrap都是必须的否则不会显示省略号;-o-text-overflow: ellipsis针对Opera;而宽度的设定主要是针对IE6;
该方法支持Internet Explorer, Safari, Chrome 和 Opera,但FF并不支持,不过可以通过Jquery来实现类似的效果。
下载这个Jquery插件:jQuery ellipsis plugin
调用方法:
1.$(document).ready(function() {
2. $('.ellipsis').ellipsis();
3.}
</body>
</html>
<head>
<style type="text/css">
ul li {
float: left;
overflow: hidden;
font-size: 12px;
margin-right: 10px;
text-indent: 0px;
}
ul li {
font-size: 12px;
width: 80px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
word-break: keep-all;
}
</style>
</head>
<body><div>
<ul>
<li>fsdfsldfsdfsdf</li>
<li>fsdfsldfsdfsdf</li>
<li>fsdfsldfsdfsdf</li>
<li>瑁卡拉我中是国人民工膛 顶替</li>
</ul>
</div>
使用text-overflow:ellipsis对溢出文本显示省略号有两个好处,一是不用通过程序限定字数;二是有利于SEO。需要使用对对溢出文本显示省略号的通常是文章标题列表,这样处理对搜索引擎更友好,因为标题实际上并未被截字,而是局限于宽度而未被显示而已。
通常的做法是这样的:
1.overflow:hidden;
2.text-overflow:ellipsis;
3.-o-text-overflow:ellipsis;
4.white-space:nowrap;
5.width:100%;
其中,overflow: hidden和white-space: nowrap都是必须的否则不会显示省略号;-o-text-overflow: ellipsis针对Opera;而宽度的设定主要是针对IE6;
该方法支持Internet Explorer, Safari, Chrome 和 Opera,但FF并不支持,不过可以通过Jquery来实现类似的效果。
下载这个Jquery插件:jQuery ellipsis plugin
调用方法:
1.$(document).ready(function() {
2. $('.ellipsis').ellipsis();
3.}
</body>
</html>