截断单行文本

来源:互联网 发布:java 替换换行符 编辑:程序博客网 时间:2024/04/30 13:33

如果不想由于单行文本过长而影响布局,通常会截取文本的一部分进行显示,并且在其末尾显示省略号。

要实现文本截断的效果,可配合使用white-space、overflow与text-overflow属性,具体样式代码如下所示。

width: 135px;white-space: nowrap;overflow: hidden;
text-overflow: ellipsis;-o-text-overflow: ellipsis;-moz-text-overflow: ellipsis; -webkit-text-overflow: ellipsis;

<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击