CSS text-overflow in a table cell?

后端 未结 12 935
情话喂你
情话喂你 2020-11-22 04:38

I want to use CSS text-overflow in a table cell, such that if the text is too long to fit on one line, it will clip with an ellipsis instead of wrapping to mult

12条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 05:12

    Specifying a max-width or fixed width doesn't work for all situations, and the table should be fluid and auto-space its cells. That's what tables are for.

    Use this: http://jsfiddle.net/maruxa1j/

    HTML:

    
        This Text Overflows and is too large for its cell.
    
    

    CSS:

    .ellipsis {
        position: relative;
    }
    .ellipsis:before {
        content: ' ';
        visibility: hidden;
    }
    .ellipsis span {
        position: absolute;
        left: 0;
        right: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    

    Works on IE9 and other browsers.

提交回复
热议问题