html - 一行中单元格上的 Colspan 似乎阻止在所有其他行中设置 TD 宽度。为什么?

标签 html html-table

我想创建一个如下所示的表:

+-----------------------------------------------------------+
|January 12th, 2012                                         |
+-----------------------------------------------------------+
| x | first item                 | second item              |
+-----------------------------------------------------------+
| x | first item                 | second item              |
+-----------------------------------------------------------+
|January 13th, 2012                                         |
+-----------------------------------------------------------+
| x | first item                 | second item              |
+-----------------------------------------------------------+
| x | first item                 | second item              |
+-----------------------------------------------------------+

但我得到的是:

+-----------------------------------------------------------+
|January 12th, 2012                                         |
+-----------------------------------------------------------+
| x            | first item           | second item         |
+-----------------------------------------------------------+
| x            | first item           | second item         |
+-----------------------------------------------------------+
|January 13th, 2012                                         |
+-----------------------------------------------------------+
| x            | first item           | second item         |
+-----------------------------------------------------------+
| x            | first item           | second item         |
+-----------------------------------------------------------+

“x”实际上是一个具有固定宽度的图像。我想强制第一个单元格只与图像一样宽。

这是一个示例:

<html>
    <body>
        <table>
            <tbody>
                <tr>
                    <td colspan="3">January 12th 2011 this here is just for padding to make table wider</td>
                </tr>
                <tr>
                    <td width="20"> x </td>
                    <td>First item</td>
                    <td>Second item</td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

似乎包含 colspan=3 的 TD 的行导致其他行中的 TD 忽略宽度属性(我也尝试使用样式 width:20px)

渲染在 FF8 中是正确的。有什么想法可以让 IE 以我想要的方式呈现表格吗?

最佳答案

我忘记了表格的样式为“表格布局:固定”,这造成了困难。设置此样式后,第一行中单元格的宽度将应用于所有后续行。由于第一行包含一个 colspan,我猜 IE 很困惑(FF 可以正常处理)。

无论如何它都没有我想要的那么灵活,但这对我有用。

<html>
  <body>
  <div style="width:350px; border:blue 1px solid">
    <table border="0" style="font-family:Arial,Helvetica;font-size:10pt;table-layout:fixed;">
      <tr>
        <td style="width:17px;"/>
        <td style="width:20px;"/>
        <td style="width:180px;"/>
        <td style="width:130px;"/>
      </tr>
      <tr>
        <td colspan="4" style="width:100%;text-align:center;font-eight:bold;background-color:#eef;">09 January 2012</td>
      </tr>
      <tr title="09 January 2012">
        <td align="center" valign="middle" colspan="1" style="width:17px;height:1.1em;"><img src="../../../../_layouts/images/WebParts2010/AWT3_Klein.png" style="border-style:None;border-width:0px;height:1.1em;width:1.1em;" /></td>
        <td align="left" valign="top" colspan="1" style="width:20px;height:1.1em;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;">LO</td>
        <td align="left" valign="top" colspan="1" style="width:180px;height:1.1em;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;">Customer Name Ltd.</td>
        <td align="left" valign="top" colspan="1" style="width:120px;height:1.1em;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;">Reason for visiting today</td>
      </tr>
    </table>
  </div>
</body>
</html>

关于html - 一行中单元格上的 Colspan 似乎阻止在所有其他行中设置 TD 宽度。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8835756/

相关文章:

css - 内容在 ie6 中被下推

php - 使用 PHP 在表格中从上到下而不是从左到右打印数组

javascript - 如何查找表格列宽并应用于同一页面中的另一个表格

javascript - 在 Javascript 中动态添加新表行

javascript - Jquery 选择器表>行>单元格>字段

javascript - 按钮未在预期位置呈现

html - nth-child 定位所有子元素

html - 关于如何识别页面主要内容的任何想法?

html - 为什么添加子 anchor 会使溢出在其父 anchor 上可见?

html - 如何在 Bootstrap 中将填充添加到 100% div?