html - 表格宽度超出了 div 边框

标签 html css

我在 div 中有表格。如果我用 IE9 或 FF 查看它就可以了。但如果我在 IE8 中查看它,表格会超出 div 边界。有什么想法吗?

<div>
  <table width="100%" >
    <tr>
      <td>
      </td>
    </tr>
  </table>
</div>

最佳答案

在这里找到解决方案:

http://www.456bereastreet.com/archive/200704/how_to_prevent_html_tables_from_becoming_too_wide/

The trick is to use the CSS property table-layout. It can take three values: auto, fixed, and inherit. The normal (initial) value is auto, which means that the table width is given by its columns and any borders. In other words, it expands if necessary.

What you want to use is table-layout:fixed. Bam! Now the table is as wide as you have specified in the CSS. No more, no less. And to my great surprise this seems to be widely supported by browsers. The only browser of any significance that does not support it is IE/Mac, and the significance of that browser is rapidly approaching zero.

Next is deciding what to do with the content that doesn’t fit in the table anymore. If the table only contains text, word-wrap:break-word (word-wrap is specified in the CSS3 Text Effects Module) will force the browser to break words as necessary to prevent overflow.

关于html - 表格宽度超出了 div 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4240986/

相关文章:

javascript - 使用 jQuery 在提交时附加一段代码

jquery - FullCalendar 上带有设计的工具提示

html - "Compile"CSS 到 HTML 作为内联样式

javascript - 按类名搜索并查找 DIV 的内容

html - 如何在 Ubuntu 上的 VS Code 中格式化 HTML 代码?

javascript - 将变量从 HTML 传递到 JS 文件

html - 为什么我的空 div 在使用 display inline 时有宽度但会折叠?

javascript - 单击文本时如何来回交换文本?

css - 导航栏折叠(Ipad 菜单)不会在 Bootstrap 中自行展开

填充模式下的 JQuery-ui Accordion 和溢出 - 无关的 2px