方法一:
<div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;"> 任意长度的字符串 </div>
说明:优点是内容可以为任何HTML元素,包括超链接和图片等,在IE6中还会在结尾自动显示省略号。缺点是必须指定宽度数值,并且宽度不能是百分数,否则在IE中会被认为是字符总长的百分比。
方法二:
<input type=”text” style=”width:100%; cursor:default; border-width:0; border-style:none; background-color:transparent;” value=”任意长度的字符串” readonly/>
说明:优点是宽度可以设为百分数。但缺点是内容只能为纯文本,不能有超链接等内容。
方法三:
.tableStyle table {
table-layout: fixed;
}
.tableStyle td {
overflow: hidden;
white-space: nowrap;
word-break: keep-all;
text-overflow: ellipsis;
}
说明:优点是没有上面两种方法的缺憾,缺点只是必须使用table。