【发布时间】:2011-04-20 19:36:37
【问题描述】:
在下面的示例中,here 也可用,WebKit(Safari 5,Chrome 10.0.648.205)和 Mozilla(FF 4)都将 DIV div 保持在浏览器窗口的可见宽度附近,而 TABLE 与它的内容。
我希望 DIV 会像 TABLE 一样宽,但由于跨浏览器的行为是一致的,我怀疑这是一个特性而不是错误。
有趣的是,如果 DIV 设置为 float:left,it does grow as wide as the table。
有什么解释吗?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Wide Table</title>
<style>
#container {
background-color:blue;
/* float:left;*/
}
</style>
</head>
<body>
<div id="container">
<table >
<tr id="tr">
<td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td><td>Table Cell</td>
</tr>
</table>
</div>
</body>
</html>
【问题讨论】:
-
你的问题回答了我的问题!浮动“增长”是我一直在寻找的。将 display 设置为 inline-block 也可以,这也是我最终决定的。