文字内容或标题过长,用 ... 进行省略的TD和DIV两种情况下的三种解决方案

DIV下的解决方案:

 

  1. <html>
  2. <head>
  3. <title>Style5.cn</title>
  4. <style type="text/css">
  5. /* 公共样式 */
  6. body { font-size: 14px; font-family:"宋体"; }
  7. a { color: Black; text-decoration: none; }
  8. a:hover { color: Blue; }
  9. /* 截取文字的盒子 */
  10. .autocut {
  11. width:200px;
  12. border:1px solid #333;
  13. overflow:hidden;
  14. white-space:nowrap;
  15. text-overflow:ellipsis;
  16. -o-text-overflow:ellipsis;
  17. -icab-text-overflow: ellipsis;
  18. -khtml-text-overflow: ellipsis;
  19. -moz-text-overflow: ellipsis;
  20. -webkit-text-overflow: ellipsis;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="autocut">
  26. <a href="http://www.style5.cn" title="TOP10热榜在图片上的半透明阴影效果">TOP10热榜在图片上的半透明阴影效果</a><br />
  27. <a href="http://www.style5.cn" title="说说最近读的书:无懈可击的Web设计">说说最近读的书:无懈可击的Web设计</a><br />
  28. </div>
  29. </body>
  30. </html>

上面的这种方案,在 IE7 和 Opera 中应该能够完美的体现出他的效果了。但是 Firefox 目前并不支持 CSS3 中的 text-overflow:ellipsis,所以这种方法还是有缺陷的,算是不完全版。

另外,在连接的 title 标签里加入完整的文章标题,这样想知道具体内容的浏览者就可以将鼠标放在连接上,看到完整的标题了。

解释一下起到关键作用的几行代码:

 

overflow :hidden ;
/
* 隐藏超出容器范围的文字 * /
white-space :nowrap ;
/
* 强制文字将不自动换行 * /
text-overflow :ellipsis ;
/
* 如果文字超出范围,将使用省略号标示出来 * /
-
o-text-overflow :ellipsis ;
/
* Opera 的私有属性,功能同上 * /
-icab-text-overflow:
ellipsis ;
-khtml-text-overflow:
ellipsis ;
-moz-text-overflow:
ellipsis ;
/
* 目前这段代码无效,为 Firefox 预留 * /
-webkit-text-overflow:
ellipsis ;

 

 

TD下的解决方案(一):

 

 

  1. 1.只需要将表格宽度固定,然后在表格的Css定义中加入:table {
  2. width:484px;
  3. table-layout:fixed;
  4. }2.然后在表格单元格的Css定义中加入:td {
  5.    overflow:hidden;
  6.    text-overflow:ellipsis;
  7. }

TD下的解决方案(二):

 

  1. <table width="200" border="1" style="table-layout:fixed;">
  2. <tr>
  3. <td width="80" style="width:80px;overflow: hidden;text-overflow:ellipsis">
  4. <nobr>我是一个兵,来自老百姓</nobr></td>
  5. <td> </td>
  6. <td> </td>
  7. </tr>
  8. </table>

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值