我想限制表格中列的宽度。
<!DOCTYPE html>
<style type="text/css">
table tr td {border:1px solid; max-width:2em; overflow:hidden; white-space:nowrap;}
</style>
<table>
<tr><td>this is looooooooo ooooooooo ooooooooooooo ooooooooo ng text</td></tr>
</table>
下一段代码在 Firefox 中运行良好(单元格的宽度有限),但在 IE9 中宽度不受限制。
最佳答案
你需要在td后面添加一个div,就像HTML中的下面这样。 div
中的任何内容都不会拉伸(stretch) table
单元格。
<!DOCTYPE html>
<table>
<tr>
<td>
<div>
this is looooooooo ooooooooo ooooooooooooo ooooooooo ng text
</div>
</td>
</tr>
</table>
CSS:
table tr td {
border:1px solid;
max-width:2em;
overflow:hidden;
white-space:nowrap;
}
div {
width: 2em;
}
在 IE8、Chrome 和 Firefox 中运行良好。
关于html - IE9 中的 td 最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14564001/