CSS word ellipsis ('…') after one or two lines

前端 未结 9 2030
执笔经年
执笔经年 2021-01-01 23:40

I\'m trying to create a word-wrap in JavaScript using CSS, and the condition is:

If DIV contains one very long word, such as \"asdasfljashglajksgkjasghk

9条回答
  •  耶瑟儿~
    2021-01-02 00:12

    Sadly, with CSS alone I don't think you can.

    http://jsfiddle.net/TVVHs/

    text-overflow: ellipsis; only works with white-space: nowrap; which prevents multiple lines.

    There probably is a crazy javascript solution that keeps chopping off words until the element height is acceptable, but that will be slow and pretty damn hacky nasty.

提交回复
热议问题