如何设置表格单元格的最大宽度?

时间:2015-05-01 12:10:25

标签: html css width max

看看这段代码:



#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;
&#13;
&#13;

如何为#test设置超长字符串 的最大宽度为20%?如果我为第二个td设置宽度,它将无法正常工作!

===

问题解决了:

word-break: break-all将起作用。谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

使用CSS属性word-wrapword-break,如下所示:

&#13;
&#13;
#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;
&#13;
&#13;