css控制文字显示长度 超过用省略号替代

[color=blue][size=medium]css控制文字显示长度 超过用省略号替代[/size][/color]

这样节省了服务器的开销,减轻服务器压力;这部分工作由客户端完成了,而且代码维护起来也方便了。

[color=blue]text-overflow 属性[/color]

CSS3 text-overflow 属性:
[url]http://www.w3school.com.cn/cssref/pr_text-overflow.asp[/url]

来张效果图:

[img]http://dl.iteye.com/upload/picture/pic/132807/b7bec964-3e3e-3a48-9f1e-ef2363d28989.png[/img]


[color=blue][size=medium]一般还配合这个属性一块使用[/size][/color]
[color=blue]overflow: hidden;[/color]
[color=blue]white-space: nowrap;[/color]
CSS3 text-overflow 属性:
[url]http://www.w3school.com.cn/cssref/pr_text_white-space.asp[/url]

日常我们为了让文字内容在一行内显示完,哪怕宽度不够也不能换行,我们可以使用white-space样式,但如果遇到了html br强制换行标签,无论是设置white-space与否都会被<br>强制换行。


[color=blue][size=medium]表格里使用text-overflow后不能隐藏超出的文本的解决方法[/size][/color]

[url]http://www.jb51.net/css/145465.html[/url]


<!DOCTYPE html>
<html>
<head>
<style>
td{
text-overflow:ellipsis;
white-space:nowrap;
overflow:hidden;
border:1px solid;
}
table{
border-collapse: collapse;
border:1px solid;
table-layout:fixed;
}
td:hover
{
text-overflow:inherit;
overflow:visible;
}
</style>
</head>
<body>

<table width="500" height="20" >
<tr>
<td width="20%" height="20">将将建军节建军节将建军节建军节积极急急急急急急急急急急急急急急急积极急急急急急急急急急急急急急急急</td>
<td width="80%" height="20">节建军节积极急急急急急急急急急急急急急急急积极急急急急急急</td>
</tr>
<tr>
<td width="20%" height="20">将将建军节建军节将建军节建军节积极急急急急急急急急急急急急急急急积极急急急急急急急急急急急急急急急</td>
<td width="80%" height="20">节建军节积极急急急急急急急急急急急急急急急积极急急急急急急</td>
</tr>
<tr>
<td width="20%" height="20">将将建军节建军节将建军节建军节积极急急急急急急急急急急急急急急急积极急急急急急急急急急急急急急急急</td>
<td width="80%" height="20">节建军节积极急急急急急急急急急急急急急急急积极急急急急急急</td>
</tr>
</table>

</body>
<html>


效果图:
[img]http://dl.iteye.com/upload/picture/pic/132809/4ceb8994-05ff-3445-85de-c348490fb948.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值