用css来实现自动截取文字

用css来实现自动截取文字,不需要后台程序和JS的使用
好处是:兼容IE,firefox,Opera;有利于内容完整性;有利于SEO;无需后台程序处理;可以在前台随时调节要截取的长度。
不好的地方:不能自动判断截取长度,当字符很短的时候在Firefox中也会生成后面的省略符号。
另外在设置截取宽度的时候,要注意,尽量让文字截取完整

<! 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 >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"   />
< title > css文字截取 </ title >
< style  type ="text/css" >
body
{font-size:13px;color:#8c966b;}
div
{clear:both;width:340px;border:1px solid #333;margin:3px;padding:3px;}
div a
{color:#8c966b;text-decoration:none;}
div a:hover
{text-decoration:underline;}

div a
{display:block;width:310px;white-space:nowrap;overflow:hidden;float:left;
    -o-text-overflow
: ellipsis;    /* for Opera */
    text-overflow
:ellipsis;        /* for IE */
}

div:after
{content:"...";padding-left:3px;font-size:12px;}/* for Firefox */
</ style >
</ head >

< body >

< div >< href ="" > 用css来实现自动截取文字,不需要后台程序和JS的使用 </ a ></ div >
< div >< href ="" > 好处是:有利于内容完整性,有利于SEO,无需后台程序处理,可以在前台随时调节要截取的长度。 </ a ></ div >
< div >< href ="" > 不好的地方:不能自动判断截取长度,当字符很短的时候在Firefox中也会生成后面的省略符号。 </ a ></ div >
< div >< href ="" > 另外在设置截取宽度的时候,要注意,尽量让文字截取完整 </ a ></ div >
< div >< href ="http://www.div-css.com" > Web标准化 www.div-css.com </ a ></ div >

</ body >
</ html >
<! 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 >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"   />
< title > css文字截取 </ title >
< style  type ="text/css" >
body
{font-size:13px;color:#8c966b;}
div
{clear:both;width:340px;border:1px solid #333;margin:3px;padding:3px;}
div a
{color:#8c966b;text-decoration:none;}
div a:hover
{text-decoration:underline;}

div a
{display:block;width:310px;white-space:nowrap;overflow:hidden;float:left;
    -o-text-overflow
: ellipsis;    /* for Opera */
    text-overflow
:ellipsis;        /* for IE */
}

div:after
{content:"...";padding-left:3px;font-size:12px;}/* for Firefox */
</ style >
</ head >

< body >

< div >< href ="" > 用css来实现自动截取文字,不需要后台程序和JS的使用 </ a ></ div >
< div >< href ="" > 好处是:有利于内容完整性,有利于SEO,无需后台程序处理,可以在前台随时调节要截取的长度。 </ a ></ div >
< div >< href ="" > 不好的地方:不能自动判断截取长度,当字符很短的时候在Firefox中也会生成后面的省略符号。 </ a ></ div >
< div >< href ="" > 另外在设置截取宽度的时候,要注意,尽量让文字截取完整 </ a ></ div >
< div >< href ="http://www.div-css.com" > Web标准化 www.div-css.com </ a ></ div >

</ body >
</ html >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值