Is it possible to wrap lots of text exactly three times, then add a more link?

亡梦爱人 提交于 2019-12-13 08:07:12

问题


I have a long description of something, it has been requested that my HTML magically detect when the text has wrapped three times, cut off the text, and add a "more..." link appended to the last of the 3rd line of the text.

Is this even possible? and if so, how do I do this? Open to Javascript, JQuery, ASP, CSS, SQL, and basic HTML suggestions.


回答1:


Unless you're using a mono-spaced font, it won't be too easy, since different letters are different width. If you are fine with a count of characters, you could calculate do a JS method and only populate a sub-string of your found length and make a link/ellipsis to denote there is more.

A method you can use to accomplish your goal is to use div tag with a height of exactly your 3 lines of text (you will have some trial/error) and specify your desired width. HTML will auto-wrap within this width. You then need to give the div tag the style property of overflow:hidden.

Doing this will hide the remaining text after 3 lines.

Then you can left/right justify a "More..." link below... I would do this programmatically in the JS so you don't have a "More..." link after a description equal or less than 3 lines.

.

.

Please rate if helpful



来源:https://stackoverflow.com/questions/8142149/is-it-possible-to-wrap-lots-of-text-exactly-three-times-then-add-a-more-link

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