文本溢出

单行文本显示省略号

 
p {
    width:100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
1.容器宽度:width(px、%都可以)
2.强制文本在一行内显示:white-space:nowrap;
3.溢出内容我隐藏:overflow:hidden;
4.溢出文本时显示省略号:text-overflow:ellipsis;
 

多行文本溢出显示省略号

 
 
a.兼容pc或移动webkit内核浏览器
p {
    overflow : hidden;
    text-overflow: ellipsis;  //溢出部分显示省略号
    display: -webkit-box;    //将对象作为弹性伸缩盒子模型显示 
    -webkit-line-clamp: 2;   //限制块元素内显示的文本行数
    -webkit-box-orient: vertical;  //设置或检索伸缩盒对象的子元素的排列方式
}
 
b.跨浏览器兼容
p{
    position: relative;
    width:200px;
    line-height: 20px;
    max-height: 40px;
    overflow: hidden;
}
p::after{
    content: "...";
    position: absolute;
    bottom: 0;
    right: 0;
    padding-left: 40px;
    background: -webkit-linear-gradient(left, transparent, #fff 55%);
    background: -o-linear-gradient(right, transparent, #fff 55%);
    background: -moz-linear-gradient(right, transparent, #fff 55%);
    background: linear-gradient(to right, transparent, #fff 55%);
    /*background:url(http://css88.b0.upaiyun.com/css88/2014/09/ellipsis_bg.png) repeat-y;*/
}
1.height高度真好是line-height的3倍;
2.结束的省略好用了半透明的png做了减淡的效果,或者设置背景颜色;
3.IE6-7不显示content内容,所以要兼容IE6-7可以是在内容中加入一个标签,比如用<span class="line-clamp">...</span>去模拟;
4.要支持IE8,需要将::after替换成:after;

转载于:https://www.cnblogs.com/onlycare/p/9263497.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值