Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

html - HTML表中的自动换行(Word-wrap in an HTML table)

I've been using word-wrap: break-word to wrap text in div s and span s.

(我一直在使用word-wrap: break-word将文本divspan 。)

However, it doesn't seem to work in table cells.

(但是,它似乎在表单元格中不起作用。)

I have a table set to width:100% , with one row and two columns.

(我有一个表设置为width:100% ,有一行和两列。)

Text in columns, although styled with the above word-wrap , doesn't wrap.

(列中的文本尽管使用上述word-wrap样式设置,但不会自动换行。)

It causes the text to go past the bounds of the cell.

(它导致文本超出单元格的边界。)

This happens on Firefox, Google Chrome and Internet Explorer.

(这发生在Firefox,Google Chrome和Internet Explorer上。)

Here's what the source looks like:

(来源如下所示:)

 td { border: 1px solid; } 
 <table style="width: 100%;"> <tr> <td> <div style="word-wrap: break-word;"> Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong word </div> </td> <td><span style="display: inline;">Short word</span></td> </tr> </table> 

The long word above is larger than the bounds of my page, but it doesn't break with the above HTML.

(上面的长字比我页面的边界大,但与上面的HTML相同。)

I've tried the suggestions below of adding text-wrap:suppress and text-wrap:normal , but neither helped.

(我尝试了以下添加text-wrap:suppresstext-wrap:normal ,但是都没有帮助。)

  ask by psychotik translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following works for me in Internet Explorer.

(以下内容适用于Internet Explorer。)

Note the addition of the table-layout:fixed CSS attribute

(请注意table-layout:fixed CSS属性的添加)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...