看看这段代码:
#test {
width: 20%;
word-break: break-all;
}

<table>
<tr>
<td id="test">
<ul>
<li>HiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiBye</li>
</ul>
</td>
<td>
Box 2: Where is its 80% width?
</td>
</tr>
</table>
&#13;
如何为#test
设置超长字符串 的最大宽度为20%?如果我为第二个td
设置宽度,它将无法正常工作!
===
问题解决了:
行word-break: break-all
将起作用。谢谢你的帮助!
答案 0 :(得分:1)
使用CSS属性word-wrap
和word-break
,如下所示:
#test {
width: 20%;
word-break: break-all;
word-wrap: break-word;
}
&#13;
<table>
<tr>
<td id="test">
<ul>
<li>HiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiByeHiBye</li>
</ul>
</td>
<td>
Box 2: Where is its 80% width?
</td>
</tr>
</table>
&#13;