【问题标题】:Wrapping table data without table-layout?在没有表格布局的情况下包装表格数据?
【发布时间】:2017-11-02 08:16:25
【问题描述】:

我需要在 <td> 元素中换行文本,但我不能使用 css table-layout 属性,因为输出是 html 电子邮件正文并且 Outlook 不支持 table-layout 属性。

是否有其他方法可以在 <td> 元素中包装文本,还是我需要在代码中手动进行换行和测量?

这是我想要实现的一个示例:

td {
  border: solid black 1pt;
  font-family: arial;
  font-size: 10pt
}

thead td{
  text-align:center;
  font-weight:bold;
}

table {
  border-collapse: collapse
}
<html>

<body>
  <table style="width:35pt;height:24pt;table-layout:fixed">
    <thead>
      <tr>
        <td style="width:35pt;height:12pt">Good</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td style="width:35pt;height:12pt;word-wrap:break-word">Costingly Cost Cost</td>
      </tr>
    </tbody>
  </table>
  
  <div style="height:50pt"></div>

  <table style="width:35pt;height:24pt;">
    <thead>
      <tr>
        <td style="width:35pt;height:12pt">Bad</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td style="width:35pt;height:12pt" nowrap>Costingly Cost Cost</td>
      </tr>
    </tbody>
  </table>
</body>

</html>

【问题讨论】:

  • 试试这个方法:HTML TD wrap text。我知道它不是用于电子邮件,而是用于一般表格。
  • 不幸的是,这不好。所有提议的解决方案都依赖于使用table-layoutmax-width css 属性; Outlook 都不支持这两种方法。
  • 这是用于电子邮件的:stackoverflow.com/questions/10096012/…
  • 这个建议似乎对我有用,如果你想把它写下来作为答案,我很乐意接受。
  • 下面为你添加答案

标签: html html-table html-email


【解决方案1】:

你可以试试这个:

<tr>
<td nowrap>Never increase, beyond what is necessary, the number of entities required to explain anything</td>
<td>Never increase, beyond what is necessary, the number of entities required to explain anything</td>

【讨论】:

  • 不幸的是,这并不完全有效,虽然文本会换行,但它会在分词处换行,这会增加 &lt;td&gt; 元素的宽度。如果我使用table-layout:fixedword-wrap:break-word,那么我会得到正确的包装,同时保持&lt;td&gt; 的宽度。我将在问题中添加一个示例 sn-p 进行详细说明。
【解决方案2】:

使用 Microsoft 专有的 word-break:break-all;

<td style="word-break:break-all;"> 

这应该可以解决问题。

【讨论】:

  • 作为任何阅读本文的人的说明,我最终得到了&lt;td style="word-break:break-all;word-wrap:break-word"&gt;,这导致 Outlook 和 Gmail 中的包装行为正确(我尚未与其他客户端进行测试)。
  • 感谢您的支持 :-)
猜你喜欢
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 1970-01-01
  • 1970-01-01
  • 2011-03-27
相关资源
最近更新 更多