How to break long words in a table td?

2019-03-12 18:47发布

This is what I have:

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

4条回答
Summer. ? 凉城
2楼-- · 2019-03-12 19:19
word-break: break-word;

This is what you want

查看更多
对你真心纯属浪费
3楼-- · 2019-03-12 19:20

I used:

word-wrap: break-word;
word-break: break-all;
table-layout: fixed;

table-layout: fixed was the key to making it work.

查看更多
Anthone
4楼-- · 2019-03-12 19:25

I think this solution will help you!

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+ */
}

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


// Edit

It's been a long time since this was accepted as the best answer and updates are required. See @benhowdle89's and @Steve's answers below.

So the current browser support is now good enough to use word-break in order to allow words to be broken over multiple lines.

word-break: break-all

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

查看更多
聊天终结者
5楼-- · 2019-03-12 19:32

All you need is

word-break:break-all

This works in Chrome 4+, IE 5.5+, FF 15+, Safari 3.1+, and Opera 15+

查看更多
登录 后发表回答