【问题标题】:HTML Div not expanding when table has width当表格有宽度时,HTML Div 不扩展
【发布时间】:2013-05-27 06:24:23
【问题描述】:

我正在使用一个表格所在的 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 应该跨越它的宽度以使表格适合里面?

【问题讨论】:

  • "我的页面上的表格没有with",那么width:1000px是多少;在桌子上?
  • 表格在我的真实页面上没有设置宽度。但为了让你明白我的意思,示例表有一个固定的宽度。问题是一样的。表格比 div 大

标签: html html-table width expand


【解决方案1】:

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

width:100%

检查这个FIDDLE

【讨论】:

    【解决方案2】:

    如果你不给你的内表任何宽度,并继续添加内容,它就可以正常工作。

    这是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>
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多