javascript - How to display text in one line and replace it with... if it exceeds the number of words?
大家讲道理
大家讲道理 2017-05-19 10:13:23
0
7
846

As in the title, the width is fixed, if the number of words exceeds the number, use... instead

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(7)
迷茫
overflow:hidden;white-space:nowrap;text-overflow:ellipsis;

overflow:hidden:超出隐藏
white-space:nowrap:强制不换行
text-overflow:ellipsis:超出省略号代替;

Portal, go check it out

为情所困

Fixed approach requires the following four conditions:
1. Fixed width
2.overflow:hidden
3.white-space:nowrap
4.text-overflow:ellipsis

小葫芦
 display: -webkit-box;
    box-orient: vertical;
    line-clamp: 3; // 可控制几行后有 ... 
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3; // 兼容写法
    overflow: hidden;
    white-space:normal;
阿神

First of all, the first point is that the line needs to be given a fixed width. Even if the width is not given, the line needs to be limited by margin. To put it bluntly, it is to give the line a fixed width. . .
Other codes are as follows

如果是一个p标签
p{
    width:100px;//固定宽度
    overflow:hidden;//超出隐藏
    white-space:nowrap;//不换行
    text-overflow:ellipsis;//省略号
}
仅有的幸福

/a/11...
Two implementation methods, fixed width, excess display..., mouse hover to omit content

巴扎黑
// line-clamp、line-height和height直接控制多行
.two-line {
    color: #333;
    line-height: 18px;
    height: 36px;
    overflow : hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    display: -moz-box;
    -webkit-line-clamp: 2;
    -moz-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    -moz-box-orient: vertical;
    box-orient: vertical;
  }
我想大声告诉你

With fixed width, use overflow:hidden;text-overflow:ellipsis;white-space:nowrap;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!