javascript - 使用以下点隐藏 DIV 中的额外内容

标签 javascript jquery html css ajax

我需要在我的 DIV 元素中隐藏点 (...) 之后的额外文本

我正在使用

<div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box">
 this is text this is text this is text this is text
</div>

结果
它隐藏了溢出 DIV 的其余内容
但我希望如果它必须隐藏,那么三个点 ... 应该放在最后,否则不要

输出需求
这是文本 这是文本 这是 te...

最佳答案

这是一个使用 text-overflow:ellipsis 的可能解决方案:

http://jsfiddle.net/FXHA3/

.ellipsis {
    width:200px;
    height:2em;
    line-height:2em;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
}

关于javascript - 使用以下点隐藏 DIV 中的额外内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17733282/

相关文章:

javascript - 如何编写 eslint 时尚模式的配置文件?

javascript - 如何使用 Javascript 从文本框中获取文本的值

javascript - 语音合成 API 阻塞主线程

javascript - 拖动任何devexpress组件时如何防止其他元素突出显示?

javascript - 在 Angular JS 中更改文本的正确方法是什么?

java - 如何将zip文件写入httpresponse

android - 使用 enter 键提交带有 android/phonegap 数字键盘的表单

php - 从代码库中删除无用文件

javascript - 导航栏多项选择

javascript - 在异步函数中返回 promise - 什么是更优雅/更好的实践解决方案?