1行
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
多行
text-overflow: ellipsis;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
- 兼容ie的方法–1
.chychxItem:nth-child(4)::after{
float: right;
content: '...';
height: 20px;
line-height: 20px;
width: 3px;
margin-top: -20px;
color: #808080;
}
.chychxItem:nth-child(4)>span{
-webkit-line-clamp: revert;
overflow: hidden;
text-overflow: clip;
height: 57px;
}
- 兼容ie–2
<!-- <div class="sldiv" style="overflow: hidden; word-break: normal; word-wrap: break-word;">
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
请问囧去我家饿哦丘吉尔我我几千万我偶偶奇文件哦亲解耦IQ将诶哦亲忘记问偶尔去哦我切剑桥闻鸡起舞我哦技巧文件哦亲我我偶尔穷耳机哦亲1IQ王炯起而且偶尔1请问囧去我家饿哦丘吉尔我我几千万我偶偶奇文件哦亲解耦IQ将诶哦亲忘记问偶尔去哦我切剑桥闻鸡起舞我哦技巧文件哦亲我我偶尔穷耳机哦亲1IQ王炯起而且偶尔1请问囧去我家饿哦丘吉尔我我几千万我偶偶奇文件哦亲解耦IQ将诶哦亲忘记问偶尔去哦我切剑桥闻鸡起舞我哦技巧文件哦亲我我偶尔穷耳机哦亲1IQ王炯起而且偶尔1
</div> -->
this.wordlimit('sldiv', 100) //无法控制中英文的时候的长短 只能固定文字数
wordlimit(cname, wordlength) {
const cname1 = document.getElementsByClassName(cname)
for (var i = 0; i < cname1.length; i++) {
var nowhtml = cname1[i].innerHTML
var nowlength = cname1[i].innerHTML.length
if (nowlength > wordlength) {
cname1[i].innerHTML = nowhtml.substr(0, wordlength) + '…'
}
}
},