Word-wrap in an HTML table

后端 未结 25 3019
温柔的废话
温柔的废话 2020-11-22 02:45

I\'ve been using word-wrap: break-word to wrap text in divs and spans. However, it doesn\'t seem to work in table cells. I have a tabl

相关标签:
25条回答
  • 2020-11-22 03:46

    The answer that won the bounty is correct, but it doesn't work if the first row of the table has a merged/joined cell (all the cells get equal width).

    In this case you should use the colgroup and col tags to display it properly:

    <table style="table-layout: fixed; width: 200px">
    <colgroup>
        <col style="width: 30%;">
        <col style="width: 70%;">
    </colgroup>
    <tr>
        <td colspan="2">Merged cell</td>
    </tr>
    <tr>
        <td style="word-wrap: break-word">VeryLongWordInThisCell</td>
        <td style="word-wrap: break-word">Cell 2</td>
    </tr>
    </table>
    
    0 讨论(0)
提交回复
热议问题