CSS实现单行、多行文本溢出显示省略号的实现方法
1,单行溢出,超出部分显示...或者截取。前提必须有宽度。 width:300px; overflow: hidden; text-overflow:ellipsis; whitewhite-space: nowrap; 效果如图: 但是这个属性只支持单行文本的溢出显示省略号,如果我们要实现多行文本溢出显示省略号呢。 接下来重点说一说多行文本溢出显示省略号,如下。 二、多行溢出 {display:-webkit-box;overflow:hidden;text-overflow:ellipsis;-webkit-line-clamp:2;-webkit-box-orient:vertical;} display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; 效果如图: 适用范围: 因使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端; 实现方法: p{position: relative; line-height: 20px; max-height: 40px;overflow: hidden;} p::after{content: "..."; position: absolute; bottombottom: 0; rightright: 0; padding-left: 40px; background: -webkit-linear-gradient(left, transparent, #fff 55%); background: -o-linear-gradient(rightright, transparent, #fff 55%); background: -moz-linear-gradient(rightright, transparent, #fff 55%); background: linear-gradient(to rightright, transparent, #fff 55%); } 适用范围: 注: 1.将height设置为line-height的整数倍,防止超出的文字露出。 脚本之家小编补充: ie核心的浏览器一定要定义line-height与高度,-webkit-line-clamp意思就是几行,例如 line-height: 20px; max-height: 40px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; -webkit-line-clamp -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit property),它没有出现在 CSS 规范草案中。 (编辑:焦作站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |