CSS text-overflow in a table cell?

后端 未结 12 917
情话喂你
情话喂你 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:23

    When it's in percentage table width, or you can't set fixed width on table cell. You can apply table-layout: fixed; to make it work.

    table {
      table-layout: fixed;
      width: 100%;
    }
    td {
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      border: 1px solid red;
    }
    Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah. Lorem ipsum and dim sum yeah yeah yeah.

提交回复
热议问题