css - Internet Explorer 中的表 colspan 相对宽度问题

标签 css internet-explorer html-table width

我使用表格来生成简单的水平图表(以便于缩放)。 我使用 colspanning 来获得精确的重叠(有时单元格彼此重叠,但在此示例中不是)。

我的问题是 IE(8) 渲染相对单元格宽度错误。

我知道单元格不能小于它的内容,但这不是这里的问题。

例如,示例中的“X 65”单元格比 IE 中的 47% 宽很多。 然而,Firefox 做得很好。

例子如下:

<html>
<body>

<style>
table.CompAnalysisTable {
    border-width: 1px;
    border-spacing: 0px;
    border-style: solid;
    border-color: black;
    border-collapse: collapse;
    background-color: white;
    font-size:8px;
}

table.CompAnalysisTable td {
    border-width: 1px;
    border-style: solid;
    border-color: black;
}

table.CompAnalysisTable td table 
{
    border-style:none;
}
</style>

<table>
<tr>
<td>
</td>
<td class="nobr" valign="middle" align="left">Graph</td>
<td valign="middle" width="100%" align="right">Total 73</td>
</tr>
</tbody>
</table>

<table class="CompAnalysisTable" width="100%" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="nobr" style="width: 47%; background-color: rgb(172, 172, 255);" colspan="65">X&nbsp;65</td>
<td class="nobr" style="width: 47%; background-color: white;" colspan="65"></td>
<td class="nobr" style="width: 5%; background-color: rgb(172, 172, 255);" colspan="7">A&nbsp;7</td>
<td class="nobr" style="width: 1%; background-color: rgb(172, 172, 255);">B&nbsp;1</td>
</tr>
<tr>
<td class="nobr" style="width: 47%; background-color: white;" colspan="65"></td>
<td class="nobr" style="width: 52%; background-color: rgb(255, 152, 152);" colspan="72">A&nbsp;72</td>
<td class="nobr" style="width: 1%; background-color: rgb(255, 152, 152);">B&nbsp;1</td>
</tr>
</table>


</body>
</html>

我已经尝试过其他技术,例如 div 和每行的单独表格,但 colspanning 是获得精确重叠的唯一技术。

另一种解决方案是在服务器上渲染图像,但我放宽了缩放比例并且非常耗时。

非常感谢任何帮助。

最佳答案

像这样的 header 可以通过将其呈现为 IE 7 来省去为 IE 8 修复它的麻烦:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 

除此之外,您可以尝试查看 IE 8 正在做什么,并使用特定的 html 条件修复它:

<!--[if IE 8]><![endif]-->

我希望我能提供更多帮助,但我没有 IE 8,所以看不到问题。
也许这些链接可以提供帮助:

HTML conditions
Beyond Doctypes

关于css - Internet Explorer 中的表 colspan 相对宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1357818/

相关文章:

vba - 我的模块结束后 Internet-Explorer 不会关闭

JavaScript 拆分功能在 IE 中不起作用

javascript - 如何通过 parent 高度获得纵横比?

css - 选择元素而不是 CSS 中的某些内部元素

javascript - 有人能帮我理解为什么这个 Javascript 除了 IE 之外在其他地方都可以工作吗?

javascript - 通过点击表头来排序

javascript - 当列隐藏在表布局为 :fixed 的表中时,IE8 不会调整 tbody 或 thead 的大小

php - 考虑字段值对表行进行着色

javascript - 覆盖 jQuery 选项卡 CSS

html - 允许 div 始终填充 div 中剩余的宽度