在下面的示例中,也可用here,WebKit(Safari 5,Chrome 10.0.648.205)和Mozilla(FF 4)都將DIV div保留在瀏覽器窗口的可見寬度周圍,而TABLE與其內容一樣寬。TABLE包含DIV
我期望DIV的增長和TABLE一樣寬,但由於行爲在瀏覽器中是一致的,我懷疑這是一個功能而不是bug。
有趣的是,如果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>
您的問題回答了我的問題!浮動「增長」是我一直在尋找的。將顯示設置爲內嵌塊也行得通,這也是我最終解決的問題。 – Chris 2012-06-21 20:44:58