div显示字符超过固定长度是显示……的方法
2016-09-18 14:07
435 查看
目前线网页遇到div显示标题的时候,如果标题过长,显示全部标题会显得很突兀,而且默认换行为首行满后再换行,有可能第二行就一个字,会很难看,这是通过CSS方法处理如下:<div style="width:754px; text-overflow:ellipsis;white-space:nowrap; overflow:hidden;">
看人家的这样写:
<pre name="code" class="html"><div style="width:100px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis; border:1px solid #000;
-moz-binding: url('ellipsis.xml#ellipsis');">说存在游览器兼容问题……???
用js不存在兼容问题:
<pre name="code" class="html">function ajustHeight(node, rows){ var v = node.innerHTML; node.innerHTML = ""; var h1 = node.offsetHeight; node.innerHTML = " "; var h2 = node.offsetHeight; var rowHeight = h2 - h1; node.innerHTML = v; var len = v.length, i = 3; while(node.offsetHeight > rowHeight * rows + h1){ node.innerHTML = v.substring(0, len - i) + '...'; i++; } } ajustHeight(document.getElementById('div1'), 2);
引用:http://bbs.csdn.net/topics/340175777
http://www.php100.com/html/webkaifa/DIV_CSS/2009/0416/2453.html
相关文章推荐
- 用css布局的方法实现如果字符超过一定长度就显示成省略号
- EXCEL某列长度超过255个字符导入SQL SERVER2005的处理方法
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- css控制一行文字超过固定长度显示省略号
- Android设置TextView显示指定个数字符,超过部分显示...(省略号)的方法
- EXCEL某列长度超过255个字符导入SQL SERVER2005的处理方法
- div显示固定长度的内容(text-overflow)
- c# 超长字符串截取固定长度后显示...(超长后面显示点点点) 通用方法
- EXCEL某列长度超过255个字符导入SQL SERVER的处理方法
- .net前台截取固定长度超出显示字符
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- LI中内容超过长度后以省略号显示的方法
- EXCEL某列长度超过255个字符导入SQL SERVER2005的处理方法
- jqgrid中实现前台界面显示字符长度固定,后面用省略号代替
- Li中内容超过长度后以省略号显示的方法
- winrar解压spring出现“路径和文件名总长度必须不能超过 260 个字符!”错误的解决方法
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- EXCEL某列长度超过255个字符导入SQL SERVER2005的处理方法
- LI中内容超过长度后以省略号显示的方法
- "路径和文件名总长度必须不能超过 260 个字符! 系统找不到指定的路径"的解决方法