css文本强制两行超出就显示省略号

1. 强制一行的情况很简单

overflow:hidden;     //超出的隐藏

text-overflow:ellipsis;  //省略号

white-space:nowrap;  //强制一行显示

2. 如果要强制两行的话,得用到css3的知识

overflow:hidden;

text-overflow:ellipsis;

display:-webkit-box;

-webkit-box-orient:vertical;

-webkit-line-clamp:2;  //以此类推,3行4行直接该数字就好啦

在实际项目中,我们会发现-webkit-box-orient没有生效,需要加入如下注释

/*! autoprefixer: off */

最终代码:

overflow: hidden;

text-overflow: ellipsis;

display: -webkit-box;

-webkit-line-clamp: 2;

/*! autoprefixer: off */

-webkit-box-orient: vertical;


原文:https://blog.csdn.net/Tracy_frog/article/details/77881808 

猜你喜欢

转载自www.cnblogs.com/cap-rq/p/9962083.html