How can I truncate long texts in a table using CSS?

前端 未结 4 602
余生分开走
余生分开走 2020-12-30 23:05

Can anyone give a CSS example of how can I create a table where long texts are truncated to texts ending with \"...\"?

Here is the example: http://jsfiddle.net/NpABe

4条回答
  •  执念已碎
    2020-12-30 23:31

    If you need truncate text for just one line use this css:

    .truncate-text-one-line{
        width:80%;
        height: 100px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    

    Otherwise, use this script:

    function shorten_text(text, maxLength) {
        var ret = text;
        if (ret.length > maxLength) {
            ret = ret.substr(0,maxLength-3) + "...";
        }
        document.write(ret);
    }
    

提交回复
热议问题