当表格有宽度时,HTML Div不会扩展

时间:2013-05-31 12:21:10

标签: html html-table width expand

我正在使用表格所在的div。 该表在我的页面上没有宽度,但它会增长。

作为测试,我尝试在div内的表格上设置宽度jsfiddle

<div style="border:1px solid black;margin:0 50px;">
<div>
<table style="border:1px solid red; width:1000px;">
<tr><td style="white-space: nowrap;">hej</td></tr>
</table>
</div>
<div style="clear:both"></div>
</div>

谁能告诉我为什么这不起作用? 例如。 div应该跨越它的宽度以使表适合内部?

2 个答案:

答案 0 :(得分:0)

尝试将%age中的宽度设置为

width:100%

检查此FIDDLE

答案 1 :(得分:0)

如果你没有为你的内部桌子提供任何宽度,并继续添加内容,它的效果非常好。

这是WORKING SOLUTION

代码:

<div style="border:1px solid black;margin:0 50px;">
<div>
<table style="border:1px solid red;">
<tr><td>The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. </td></tr>
</table>
</div>
<div style="clear:both"></div>
</div>

我希望这会有所帮助。