Ellipsis in the middle of a text (Mac style)

后端 未结 15 2264
长情又很酷
长情又很酷 2020-11-29 03:04

I need to implement ellipsis (\"...\") in the middle of a text within a resizable element. Here is what it might look like. So,

\"Lorem ipsum do         


        
15条回答
  •  半阙折子戏
    2020-11-29 03:21

    So my colleague came up with a solution that uses no extra dom elements. We check to see if the div overflows and add a data attribute of the last n characters. The rest is done in css.

    Here is some HTML:

    This is my text it is awesome
    This is my text

    And the css:

    .box {
        width: 200px;
    }
    
    .ellipsis:before {
        float: right;
        content: attr(data-tail);
    }
    
    .ellipsis {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    

    Here is the obligatory jsfiddle for this: http://jsfiddle.net/r96vB/1/

提交回复
热议问题