2017-06-01 22 views
0

我需要將文本包裝到<td>元素中,但我無法使用css table-layout屬性作爲輸出到html電子郵件正文,並且Outlook不支持table-layout屬性。無表格佈局的表格數據包裝?

是否有其他方式來包裝<td>元素中的文本,還是我需要在代碼中手動執行換行和測量?

這裏是什麼,我想acheive一個例子:

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>

+0

試一試這個方法:[HTML TD wrap text](https://stackoverflow.com/questions/1057574/html-td-wrap-text)。我知道它不適用於電子郵件,而是一般的表格。 – Syfer

+0

不幸的是,這並不好。所有建議的解決方案都依賴於使用'table-layout'或'max-width' css屬性;這兩者都不被Outlook支持。 –

+0

這是電子郵件:https://stackoverflow.com/questions/10096012/break-long-words-in-html-email-in-outlook-2010 – Syfer

回答

1

使用微軟的專有詞-break:盈虧所有;

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

這應該解決問題。

+1

作爲讀者閱讀的一個提示,我最終使用了',這導致了Outlook和Gmail的正確包裝行爲我還沒有與其他客戶進行過測試)。 –

+0

謝謝K你一個人:-) – Syfer

0

你可以試試這個:

<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> 

+0

不幸的是,當文本沒有換行時,它會在可能增加'​​'元素寬度的單詞分隔處換行。如果我使用'table-layout:fixed'和'word-wrap:break-word',那麼我會在保持'​​'的寬度的同時得到正確的包裝。我將在這個問題中添加一個示例代碼片段來詳細說明。 –