简体   繁体   English

为什么自动换行不起作用?

[英]Why is word-wrap not working?

My word-wrap is not working at all我的自动换行根本不起作用

 <table border="1" style="width:100%"> <thead> <tr> <th>very long word</th> </tr> </thead> <tbody> <tr> <td style="word-wrap:break-word;">ablkasd/123123123/agsdfasdf/asdfasdfasdf/_sdfsdfsdf{123123-14werwwer-14124124-wefweshtsdf-235232323}/3235235/dasasdfasdfasdf.bsfs</td> </tr> </tbody> </table>

The string is not breaking and is always in one line.字符串没有断裂,并且始终在一行中。

I already tried all solutions from Word Wrap not working properly but still not working我已经尝试了Word Wrap 的所有解决方案都无法正常工作,但仍然无法正常工作

You will need to add table-layout: fixed; 你需要添加table-layout: fixed; to the table: 到桌子:

 table {width:100%; table-layout: fixed;} table td {word-wrap:break-word;} 
 <table> <thead> <tr> <th>very long word</th> </tr> </thead> <tbody> <tr> <td>ablkasd/123123123/agsdfasdf/asdfasdfasdf/_sdfsdfsdf{123123-14werwwer-14124124-wefweshtsdf-235232323}/3235235/dasasdfasdfasdf.bsfs</td> </tr> </tbody> </table> 

Although the answer has been accepted, I would like to add to the accepted answer that apart from虽然答案已被接受,但我想补充一点,除了

table td {word-wrap:break-word;}

you need to ensure that the white-space property is not set to nowrap or pre .您需要确保white-space属性未设置为nowrappre

This can prevent your td content word-wrapping even if you apply word-wrap: break-word即使您应用自动换行,这也可以防止您的 td 内容自动换行:break-word

If some other css styles is setting you td white-space property, you can add如果其他一些 css 样式正在为您设置 td white-space 属性,您可以添加

table td {
word-wrap:break-word;
white-space: normal;
}

This will ensure your td content has proper word-wrapping.这将确保您的 td 内容具有正确的自动换行。

Hope it helps someone!希望它可以帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM