CSS文本溢出用省略号代替

语法: 
  text-overflow : clip | ellipsis 
 
  参数: 
  clip :  不显示省略标记(...),而是简单的裁切
   (clip这个参数是不常用的!)
  ellipsis :  当对象内文本溢出时显示省略标记(...)
 
  说明: 
  设置或检索是否使用一个省略标记(...)标示对象内文本的溢出。

  请您注意,text-overflow:ellipsis属性在FF中是没有效果的。


  text-overflow属性仅是注解,当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。我们想要实现溢出时产生省略号的效果。还必须定义:强制文本在一行内显示(white-space:nowrap)及溢出内容为隐藏(overflow:hidden)。只有这样才能实现溢出文本显示省略号的效果。

[css]  view plain copy
  1. .ellipsis {  
  2.     width:300px;  
  3.     white-spacenowrap;  
  4.     overflowhidden;  
  5.     text-overflow: ellipsis;  
  6.   
  7. }  

为了适应多种浏览器,可以写这下面这样:

[css]  view plain copy
  1. .ellipsis {  
  2.     width180px;   
  3.     white-spacenowrap;  
  4.     overflowhidden;  
  5.     text-overflow: ellipsis;  
  6.     -o-text-overflow: ellipsis; /*For Opera*/  
  7.     -ms-text-overflow: ellipsis; /*For IE8*/  
  8.     -moz-binding: url(assets/xml/ellipsis.xml#ellipsis); /*For Firefox3.x*/  
  9. }  
为了在firefox中可用,需要创建XUL,它应该被保存为ellipsis.xml:

[html]  view plain copy
  1. <?xml version="1.0"?>  
  2. <bindings   
  3.   xmlns="http://www.mozilla.org/xbl"  
  4.   xmlns:xbl="http://www.mozilla.org/xbl"  
  5.   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"  
  6. >  
  7.     <binding id="ellipsis">  
  8.         <content>  
  9.             <xul:window>  
  10.                 <xul:description crop="end" xbl:inherits="value=xbl:text"><children/></xul:description>  
  11.             </xul:window>  
  12.         </content>  
  13.     </binding>  
  14. </bindings>  

把它保存在assets/xml/ellipsis.xml#ellipsis目录中。  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值