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

前端 未结 9 2031
执笔经年
执笔经年 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:32

    Displaying the ellipsis needs to be handled differently when the width of container is fixed and percentage.

    • When width of container is fixed

        .nooverflow{
            display: inline-block;
            overflow: hidden;
            overflow-wrap: normal;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

    • When width of container is in percentage or auto, in this scenario define another tag in that container to render the text and specify width as 0 and min-width as 100%, that way it will take the width of container and show the ellipsis. Below is the LESS class to be used:

        .nooverflow{
            display: inline-block;
            overflow: hidden!important;
            overflow-wrap: normal;
            text-overflow: ellipsis;
            white-space: nowrap!important;
            width: 0;
            min-width: 100%;
        }

提交回复
热议问题