我的CSS:
#content_right_head span
{
display:inline-block;
width:180px;
overflow:hidden !important;
}
现在它显示内容内容
但是我想展示 内容内容…
我需要在内容后面显示点。内容动态地来自数据库。
我的CSS:
#content_right_head span
{
display:inline-block;
width:180px;
overflow:hidden !important;
}
现在它显示内容内容
但是我想展示 内容内容…
我需要在内容后面显示点。内容动态地来自数据库。
当前回答
你可以试试这个:
.classname { 宽度:250 px; 溢出:隐藏; 文本溢出:省略; }
其他回答
var tooLong = document.getElementById("longText").value;
if (tooLong.length() > 18){
$('#longText').css('text-overflow', 'ellipsis');
}
如果您使用的是text-overflow:ellipsis,浏览器将尽可能地显示该容器中的内容。但是,如果您想指定圆点之前的字母数或剥离一些内容并添加圆点,则可以使用下面的函数。
function add3Dots(string, limit)
{
var dots = "...";
if(string.length > limit)
{
// you can also use substr instead of substring
string = string.substring(0,limit) + dots;
}
return string;
}
叫喜欢
add3Dots("Hello World",9);
输出
Hello Wor...
在这里看到它的行动
函数add3Dots(字符串,限制) { Var dots = "…"; 如果字符串。长度>限制) { //你也可以用substr代替substring String = String .substring(0,limit) + dots; } 返回字符串; } console.log(add3Dots("你好,你今天过得怎么样?",10));
首先,你做一个div标签设置宽度,在里面做p标签,然后添加文本,并应用下面给出的代码。 当你的p标签达到div标签的宽度时,“…”将被应用。
-
列表项
`div > p{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;}`
我认为你正在寻找文本溢出:省略与空白:nowrap结合
点击这里查看更多细节
好吧,“文本溢出:省略号”为我工作,但只是如果我的限制是基于'宽度',我需要一个解决方案,可以应用于行(在'高度'而不是'宽度'),所以我做了这个脚本:
function listLimit (elm, line){
var maxHeight = parseInt(elm.css('line-Height'))*line;
while(elm.height() > maxHeight){
var text = elm.text();
elm.text(text.substring(0,text.length-10)).text(elm.text()+'...');
}
}
当我必须,例如,我的h3只有2行,我做:
$('h3').each(function(){
listLimit ($(this), 2)
})
我不知道这是否是性能需求的最佳实践,但对我来说是有效的。