Add three dots in a multiline span

后端 未结 3 1878
终归单人心
终归单人心 2020-12-29 23:47

I found this question here on SO and the solution is pretty simple:

jsfiddle: http://jsfiddle.net/Y5vpb/

html:

Lorem Ipsum is s         


        
相关标签:
3条回答
  • 2020-12-29 23:58

    add width: 200px; and white-space: nowrap; to your .text css block. With no width set, the text just expands and fills in.

    0 讨论(0)
  • 2020-12-30 00:08
    span{
        display: block; /* Fallback for non-webkit */
        display: -webkit-box;
        -webkit-line-clamp: 3; /* no of lines */
        text-overflow: ellipsis;
        overflow:hidden !important;
        width:180px;
    }
    

    above CSS property 'll put three dots...
    eg:

    Lorem Ipsum is simply dummy
    text of the printing and
    typesetting industry. Lorem...

    0 讨论(0)
  • 2020-12-30 00:13

    The specification for the text-overflow property says that this is not possible for multiline text:

    This property specifies rendering when inline content overflows its block container element ("the block") in its inline progression direction that has ‘overflow’ other than ‘visible’. Text can overflow for example when it is prevented from wrapping (e.g. due to ‘white-space:nowrap’ or a single word is too long to fit).

    In other words, only works on single line text blocks.

    source: http://dev.w3.org/csswg/css3-ui/#text-overflow

    EDIT This fiddle has a workaround using jquery: http://jsfiddle.net/k5VET/ (source: Cross browsers mult-lines text overflow with ellipsis appended within a width&height fixed div?)

    0 讨论(0)
提交回复
热议问题