如何打破表td中的长词?

Guy*_*ere 17 css words html-table long-integer

这就是我所拥有的:

<td style='width:500px; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;'>

Ste*_*eve 35

我用了:

word-wrap: break-word;
word-break: break-all;
table-layout: fixed;
Run Code Online (Sandbox Code Playgroud)

table-layout: fixed 是让它发挥作用的关键.

  • `word-break:break-all`为我做了. (10认同)

ben*_*e89 14

word-break: break-word;
Run Code Online (Sandbox Code Playgroud)

这就是你想要的


Red*_*Red 14

我认为这个解决方案会对你有帮助!

pre {
    white-space: pre;           /* CSS 2.0 */
    white-space: pre-wrap;      /* CSS 2.1 */
    white-space: pre-line;      /* CSS 3.0 */
    white-space: -pre-wrap;     /* Opera 4-6 */
    white-space: -o-pre-wrap;   /* Opera 7 */
    white-space: -moz-pre-wrap; /* Mozilla */
    white-space: -hp-pre-wrap;  /* HP Printers */
    word-wrap: break-word;      /* IE 5+ */
}
Run Code Online (Sandbox Code Playgroud)

http://perishablepress.com/press/2010/06/01/wrapping-content/


//编辑

这已经很长时间了,因为这被认为是最好的答案,需要更新.请参阅下面的@ benhowdle89和@ Steve的答案.

因此,当前的浏览器支持现在足以使用word-break,以便允许在多行上分割单词.

word-break: break-all

http://caniuse.com/#feat=word-break


jos*_*und 5

所有你需要的是

word-break:break-all

这适用于Chrome 4+、IE 5.5+、FF 15+、Safari 3.1+ 和 Opera 15+