IE 不尊重 td 宽度

发布于 2024-11-09 19:17:39 字数 829 浏览 0 评论 0原文

我有一个基于表格的布局,分为四列,其中两列用于填充目的。在大多数浏览器中,它工作正常,但至少在 IE9 上,在正常模式和兼容模式下,单元格的大小都不是应有的大小。

我尝试将宽度定义为属性和 CSS 样式,但似乎都没有帮助。 请参阅 fiddle 进行演示。

我想要:

+------------------------------------------+
|  320          | 20 | 39   |  320         |
|               |    |      |              |
+------------------------------------------+

我得到:(四舍五入,值是小数)

+------------------------------------------+
|  324          | 19 | 34   |  321         |
|               |    |      |              |
+------------------------------------------+

使用实际内容而不是占位符内容,差异甚至更加夸张,最左边的列是357,最右边的299 像素宽。

我最初只有两列边缘有填充,但切换到当前版本作为尝试修复。但没有效果。

这是针对 HTML 新闻通讯的,因此不能选择使用无表格布局。

I have a table based layout which is divided into four columns, the two of them for padding purposes. In most browsers it works fine, but at least on on IE9 in both normal and compatibility mode the cells aren't the size they're supposed to be.

I've tried defining the width as both attributes and CSS styles but neither seems to help. See fiddle for a demonstration.

I want:

+------------------------------------------+
|  320          | 20 | 39   |  320         |
|               |    |      |              |
+------------------------------------------+

I get: (rounded, values are decimals)

+------------------------------------------+
|  324          | 19 | 34   |  321         |
|               |    |      |              |
+------------------------------------------+

With the actual content instead of the placeholder stuff the difference is even more exaggerated, the leftmost column being 357 and the rightmost 299 pixels wide.

I originally had only two columns with padding on the edges, but switched to the current version as an attempted fix. It had no effect.

This is for an HTML newsletter so using a tableless layout is not an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

栩栩如生 2024-11-16 19:17:39

过去,我发现这几乎是一个不可能解决的问题,除非您让其中一个表格元素没有固定宽度。

如果您这样做,那么我发现该列将是调整大小的列,而其余列应采用您要求的大小。

这并不理想,但至少是合理可预测和可控的。

In the past, I've found this to be a virtually impossible issue to resolve unless you leave one of your table elements without a fixed width.

If you do that, then I've found that column will be the one that resizes, while the rest should take the size you ask for.

It's not ideal, but at least it's reasonably predicable and controllable.

香橙ぽ 2024-11-16 19:17:39

有助于查看您的 CSS 和 HTML。但在测量表格的总宽度时,不要忘记边框数。

边距+边框+内边距+宽度=实际宽度。

另外,请确保这些单元格之一中没有任何大于单元格宽度的元素。

Would help to see your CSS and HTML. But don't forget borders count when measuring the total width of a table.

margin + border + padding + width = real width.

Also, make sure you don't have any element in one of those cell that is bigger than the cell width.

清音悠歌 2024-11-16 19:17:39

我终于找到了解决问题的方法。四个单元格本身很好,但是包含时事通讯标题和入口的这段代码破坏了它:

<tr><td colspan="4">Some long text here</td></tr>

我将其更改为这样,它开始工作:

<tr><td colspan="4" width="700">Some long text here</td></tr>

无论我是否强制它,宽列的宽度都是 700px,但如果我不这样做,单列单元格的宽度变得混乱。我认为这是 IE 中的一个明显错误。

I finally found a solution to the problem. The four cells themselves were fine, but this code containing the newsletter heading and ingress broke it:

<tr><td colspan="4">Some long text here</td></tr>

I changed it to this and it started working:

<tr><td colspan="4" width="700">Some long text here</td></tr>

The wide column's width is 700px whether or not I force it, but if I don't, the width of the single column cells gets messed up. I consider this a clear bug in IE.

在你怀里撒娇 2024-11-16 19:17:39
<table width="699" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="320" height="50" valign="top"><!--test--> </td>
    <td width="20" valign="top"><!--test--> </td>
    <td width="39" valign="top"><!--test--> </td>
    <td width="320" valign="top"><!--test--> </td>
  </tr>
</table>

这应该有效

<table width="699" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="320" height="50" valign="top"><!--test--> </td>
    <td width="20" valign="top"><!--test--> </td>
    <td width="39" valign="top"><!--test--> </td>
    <td width="320" valign="top"><!--test--> </td>
  </tr>
</table>

this should work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文