Word-wrap in an HTML table

后端 未结 25 2893
温柔的废话
温柔的废话 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:34

    Change your code

    word-wrap: break-word;
    

    to

    word-break:break-all;
    

    Example

    <table style="width: 100%;">
      <tr>
        <td>
          <div style="word-break:break-all;">longtextwithoutspacelongtextwithoutspace Long Content, Long Content, Long Content, Long Content, Long Content, Long Content, Long Content, Long Content, Long Content, Long Content</div>
        </td>
        <td><span style="display: inline;">Short Content</span>
        </td>
      </tr>
    </table>

    0 讨论(0)
  • 2020-11-22 03:34

    Just add width. This worked for me.

         <td style="width:10%;"><strong>Item Name</strong></td>
    
    0 讨论(0)
  • 2020-11-22 03:35

    The following works for me in Internet Explorer. Note the addition of the table-layout:fixed CSS attribute

    td {
      border: 1px solid;
    }
    <table style="table-layout: fixed; width: 100%">
      <tr>
        <td style="word-wrap: break-word">
          LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongWord
        </td>
      </tr>
    </table>

    0 讨论(0)
  • 2020-11-22 03:35
    <p style="overflow:hidden; width:200px; word-wrap:break-word;">longtexthere<p>
    
    0 讨论(0)
  • 2020-11-22 03:37

    i have same issue this work fine for me

     <style> 
          td{
                word-break: break-word;
          }
        </style>
        <table style="width: 100%;">
          <tr>
    <td>Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong word</td>
            <td><span style="display: inline;">Short word</span></td>
          </tr>
        </table>
    
    0 讨论(0)
  • 2020-11-22 03:39

    This works for me:

    <style type="text/css">
        td {
    
            /* CSS 3 */
            white-space: -o-pre-wrap;
            word-wrap: break-word;
            white-space: pre-wrap;
            white-space: -moz-pre-wrap;
            white-space: -pre-wrap;
        }
    

    And table attribute is:

       table {
          table-layout: fixed;
          width: 100%
       }
    
    </style>
    
    0 讨论(0)
提交回复
热议问题