[英]Why is word-wrap not working?
我的自動換行根本不起作用
<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>
字符串沒有斷裂,並且始終在一行中。
我已經嘗試了Word Wrap 的所有解決方案都無法正常工作,但仍然無法正常工作
你需要添加table-layout: fixed;
到桌子:
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>
雖然答案已被接受,但我想補充一點,除了
table td {word-wrap:break-word;}
您需要確保white-space屬性未設置為nowrap或pre 。
即使您應用自動換行,這也可以防止您的 td 內容自動換行:break-word
如果其他一些 css 樣式正在為您設置 td white-space 屬性,您可以添加
table td {
word-wrap:break-word;
white-space: normal;
}
這將確保您的 td 內容具有正確的自動換行。
希望它可以幫助某人!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.