文字显示省略号

本文介绍如何使用CSS来实现单行或多行文本的省略号效果,包括不同浏览器下的兼容性处理方案,并提供了具体的代码示例。

单行文字显示省略号:设置元素的宽度,然后用onbr标签里面放文字然后设置overflow为hidden然后设置text-overflow:ellipsis;

多行文字显示省略号:(移动端)

  1. overflow : hidden;
  2. text-overflow: ellipsis;
  3. display: -webkit-box;
  4. -webkit-line-clamp: 2;
  5. -webkit-box-orient: vertical;
浏览器兼容:比较靠谱简单的做法就是设置相对定位的容器高度,用包含省略号(…)的元素模拟实现;
p {
    position:relative;
    line-height:1.4em;
    /* 3 times the line-height to show 3 lines */
    height:4.2em;
    overflow:hidden;
}
p::after {
    content:"...";
    font-weight:bold;
    position:absolute;
    bottom:0;
    right:0;
    padding:0 20px 1px 45px;
    background:url(http://www.css88.com/wp-content/uploads/2014/09/ellipsis_bg.png) repeat-y;
}

 

具体实现网址:http://www.css88.com/archives/5206

word-spacing(即字间隔):
This is some text. This is some text.

This is some text. This is some text.

letter-spacing (字符间距):

T h i s i s h e a d e r 4

转载于:https://www.cnblogs.com/yanaweb/p/5067695.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值