[英]Text-Overflow Ellipsis not working for multi-line text boxes
Why is it so hard to have this: 为什么这么难:
DIV
with multiple lines of text DIV
带有多行文字 The following JSFiddle shows a demo. 以下JSFiddle显示了一个演示。
Questions : 问题 :
.chrome
css) in JSFiddle .chrome
css) Example : 示例 :
.truncate { border-width: 1px; border-style: solid; border-color: #aaaaaa; padding: 10px; margin-bottom: 10px; width: 260px; overflow: hidden; display: block; box-sizing: border-box; -moz-box-sizing: border-box; } .truncate.ellipsis { height: 50px; text-overflow: ellipsis; } .truncate.ellipsis.chrome { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
<div class="truncate"> No truncating at all, height adjusts to text: abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk </div> <div class="truncate ellipsis"> Truncating at 50px height: abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk </div> <div class="truncate ellipsis chrome"> Truncating at 50px height: abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk abcdefghijk </div>
There is currently no cross browser way to do this. 目前没有跨浏览器方式来执行此操作。 That said, there are a few approches you could try:
也就是说,您可以尝试一些方法:
:after
pseudo element and to absolutely position it on the bottom right corner of your DIV :after
伪元素并将其绝对放置在DIV的右下角 Example of that last one: 最后一个示例:
HTML: HTML:
<div class="ellipsis-div">
<p>Long text Cras justo odio, dapibus ac facilisis in, egestas eget quam. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.<p>
</div>
CSS: CSS:
.ellipsis-div {
position: relative;
width: 150px;
height: 150px;
overflow: hidden;
}
.ellipsis-div:after {
position: absolute;
display: block;
content: "...";
bottom: 0;
right: 0;
background-color: white;
}
You will need to tweak the position of the :after
element depending on your DIV's line-height, etc... 您将需要调整
:after
元素的位置,具体取决于您的DIV的线高等...
show ... (ellipsis) for Chrome, Firefox, IE etc. show ...(省略号)适用于Chrome,Firefox,IE等
.truncate {
width:240px;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
}
see this link: https://jsfiddle.net/n2Lvnqmc/3/ 看到这个链接: https : //jsfiddle.net/n2Lvnqmc/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.