Sun*_*uja 5 html javascript jquery-mobile
我需要将文本显示为段落,但只显示三行并在段落末尾添加 ...(三个点)时截断测试。
Isr*_*imu 15
.class-name {
display: block;
white-space: nowrap;
width: 15em;
overflow: hidden;
text-overflow: ellipsis;
}Run Code Online (Sandbox Code Playgroud)
<div style="height: 15vh; padding: 10px;
background:#dee0e5">
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum is simply dummy text of the printing and typesetting industry</span>
</div>
<div style="height: 15vh;padding: 10px; margin-top:5px;
background:#aff8af">
<span class="class-name">Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum is simply dummy text of the printing and typesetting industry</span>
</div>Run Code Online (Sandbox Code Playgroud)
zav*_*avg 12
计算可以放入 3 行的字符串的最大长度并使用以下脚本
var maxLength = 140;
var result = yourString.substring(0, maxLength) + '...';
Run Code Online (Sandbox Code Playgroud)
我使用与@zavg 相同的逻辑,并进行了一些改进:
…字符。function truncate(source, size) {
return source.length > size ? source.slice(0, size - 1) + "…" : source;
}
var res = truncate('Truncate text to fit in 3 lines', 14);
console.log(res);Run Code Online (Sandbox Code Playgroud)
尝试以下 css 属性:
.your-class-name {
text-overflow: ellipsis;
-webkit-line-clamp: 3;
line-clamp: 3;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18024 次 |
| 最近记录: |