How to replace first overflown element with ellipsis “…”

女生的网名这么多〃 提交于 2019-12-12 02:22:29

问题


I have a div with mutiple <p> tags inside it, the div is fixed width and height and I want to replace just the text that overflows the parent with "..."

<div class="container" style="width:200px; height:400px; overflow:hidden;">
   <p class="pText">one one one one one one one one one one one one </p>
   <p class="pText" >two two two two two two two two two two two two </p>
   <p class="pText">three three three three three three three three </p>
   <p class="pText">four four four four four four four four four four </p>
   <p class="pText">five five five five five five five five five five </p>
   <p class="pText">six six six six six six six six six six six six six </p>
</div>

at some point the text overflows the parent, at which point i want to replace the overflow word with "...".

like so:

___________________________
| one one one one one one |
| two two two two two two |
| two two                 |
| three three three three |
| three three three       |
| four four four four four|
| four                    |
| five five five five ... |
|_________________________|

thing is the text wraps horizontally just fine. it gets clipped vertically once its too long which is fine. what i need is to completley remove the line that is semi-visible and replace the last word before it with "..."

i guess its impossible by CSS so i dont mind trying with jQuery.

thanks alot for your help!


回答1:


This is a solution I often use:

Multiline Ellipsis in pure CSS

There is also a jQuery plugin: dotdotodt



来源:https://stackoverflow.com/questions/15729527/how-to-replace-first-overflown-element-with-ellipsis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!