CSS实现table td中文字的省略与显示

所谓省略就是把多余的字以“...”显示出来,而显示则是当鼠标移动到td上时,把省略的字重新显示出来。对于一个table,兼容IE与FF、Chrome的省略方式CSS写法:

 1 table{
 2     width:200px;
 3     table-layout: fixed;
 4 }
 5 .autocut{
 6     overflow:hidden;
 7     white-space:nowrap;
 8     text-overflow:ellipsis;
 9     -o-text-overflow:ellipsis;
10     -icab-text-overflow: ellipsis;
11     -khtml-text-overflow: ellipsis;
12     -moz-text-overflow: ellipsis;
13     -webkit-text-overflow: ellipsis;
14 }
15 .autocut:hover
16 {
17     overflow:visible;
18     white-space:normal;
19     word-wrap: break-word;
20 }

使用时,把autocut赋给td的clss类,即可:

 1 <table>  
 2     <thead>  
 3         <tr>  
 4             <th>Column1</th>  
 5             <th>Column2</th>  
 6         </tr>  
 7     </thead>  
 8     <tbody>  
 9         <tr>  
10             <td>Column1</td>  
11             <td class="autocut">
12         自动剪裁吧!自动剪裁吧!
13         </td> 
14         </tr>
15     </tbody>
16 </table>

特别需要注意的是,在HTML文件一定要加上这句声明:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

否则IE就不起作用啦,当然,由于IE6对hover的支持只到a标签,所以IE6就不能这样通过css来显示了(可以给td内部加上a标签,然后设置其css,或者通过js来处理事件),效果图:

转载请注明原址:http://www.cnblogs.com/lekko/archive/2013/04/30/3051638.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值