Insert ellipsis (…) into HTML tag if content too wide

后端 未结 24 3014
名媛妹妹
名媛妹妹 2020-11-22 10:07

I have a webpage with an elastic layout that changes its width if the browser window is resized.

In this layout there are headlines (h2) that will have

24条回答
  •  执笔经年
    2020-11-22 10:45

    There's actually a pretty straightforward way to do this in CSS exploiting the fact that IE extends this with non-standards and FF supports :after

    You can also do this in JS if you wish by inspecting the scrollWidth of the target and comparing it to it's parents width, but imho this is less robust.

    Edit: this is apparently more developed than I thought. CSS3 support may soon exist, and some imperfect extensions are available for you to try.

    • http://www.css3.info/preview/text-overflow/
    • http://ernstdehaan.blogspot.com/2008/10/ellipsis-in-all-modern-browsers.html

    That last one is good reading.

提交回复
热议问题