div里面的内容超出自身高度时,显示省略号
来源:互联网 发布:sql server union 编辑:程序博客网 时间:2024/05/24 03:19
1.给DIV设置属性:width: 200px; text-overflow: ellipsis; overflow: hidden; 当div里面的内容总宽度找过 200PX的时候,超出的部分会以“...”的形式显示。
2.上面那个案例之适用于单行文本的现实,才会有效。但当div里面的内容出现多行的时候则不能达到预期的效果。下面是解决多行的时候显示“...”的方案。
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(function () {
- $(".figcaption").each(function (i) {
- var divH = $(this).height();
- var $p = $("p", $(this)).eq(0);
- while ($p.outerHeight() > divH) {
- $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
- };
- });
- });
- </script>
- <style>
- .figcaption
- {
- background: #EEE;
- width: 410px;
- height: 3em;
- margin: 1em;
- }
- .figcaption p
- {
- margin: 0;
- line-height: 1.5em;
- }
- </style>
- </head>
- <body>
- <div class="figcaption">
- <p>
- You probably can't do it (currently?) without a fixed-width font like Courier. With
- a fixed-width font every letter occupies the same horizontal space, so you could
- probably count the letters and multiply the result with the current font size in
- ems or exs. Then you would just have to test how many letters fit on one line, and
- then break it up.</p>
- </div>
- </body>
- </html>
0 0
- div里面的内容超出自身高度时,显示省略号
- div里面的内容超出自身高度时,显示省略号
- 超出宽度的内容显示省略号
- CSS 实现表格内容超出用省略号显示 超出div显示省略号
- 内容超出后显示省略号
- 让超出DIV宽度范围的文字自动显示省略号...
- 固定DIV高度 当内容超出高度时被隐藏
- html如何实现让超出的内容显示为省略号
- 超出div宽度范围的文字进行省略号省略,在鼠标移上去以后显示完整的内容
- 当页面内容溢出或超出边界时显示省略号
- TextView限制多行,超出内容时用省略号显示
- 网页div文字溢出(超出)显示省略号
- html div 不换行超出显示省略号
- html div 不换行超出显示省略号
- JQuery 控制超出内容显示省略号
- 表格内容超出用省略号显示
- 文本内容超出后显示省略号效果
- css实现文字内容超出显示省略号
- CSS position: absolute、relative定位问题不详解
- return false
- CSS样式表继承小结
- 扩展
- CSS文本超出2行就隐藏并且显示省略号
- div里面的内容超出自身高度时,显示省略号
- CSS颜色渐变
- CSS3 box-sizing属性
- CSS3阴影 box-shadow的使用和技巧总结
- poj 2240 Arbitrage(floyd/bellman判正圈)
- JavaScript字符串转换成数字的三种方法
- CSS3属性选择器
- CSS中伪类选择器及伪元素
- 如何将word文档转换成电子书?