html - 为什么 IE 不尊重带有流体图像子项的表格宽度

标签 html css internet-explorer html-table fluid-layout

考虑 the following code :

HTML:

<table>
    <tr>
       <td><img src="http://watduck.jpg.to" /></td>
    </tr>
</table>

CSS:

table { width: 10% }
img { max-width: 100% }

图像显然应该是窗口宽度的十分之一,这正是除了 IE 之外的所有浏览器中的宽度,它只是回落到其原始大小。

然而,consider this :

HTML:

<div><img src="http://watduck.jpg.to" /></div>

CSS:

div { width: 10% }
img { max-width: 100% }

哪个 IE 确实正确,并显示在窗口宽度的十分之一处。


那么,问题来了:是什么导致了这种行为,可以做些什么来强制 IE 遵守表格的宽度?

已在 IE8 和 IE9 中测试(不关心 IE7 及以下版本)。

最佳答案

如果您在表格 css 中指定 table-layout: fixed; 它会起作用。

标准中关于表格布局的术语似乎有些矛盾。特别是,table-layout: auto; 是这样说的:

The column width is set by the widest unbreakable content in the cells

由于图像内容是牢不可破的,它将单元格的宽度设置为内容的大小。最大宽度似乎被它覆盖了。

关于html - 为什么 IE 不尊重带有流体图像子项的表格宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9147255/

相关文章:

javascript - 当我传递 ID 时,AngularJS 点击不起作用

java - 替换JSP中的HTML特殊字符

html - 溢出-x : auto on iPhone is not scrolling

internet-explorer - 导致 IE 问题的 HTTP header ?

internet-explorer - AppActivate 并不总是激活应用程序窗口

java - 在 Eclipse 动态 Web 项目中包含 HTML 文件

html - 上传到服务器时不显示背景图像

javascript - 所有页面都出现 float 窗口

html - 使用 flex 时在 div 而不是整个页面上滚动

javascript - d3 svg 绘制矩形条形图在 IE11 中不起作用