Table 具有 rowspan 和 table-layout fixe 时的列宽

Table column width when having rowspan and table-layout fixe

我无法固定 html table 第二列的宽度。

下面是我的 table:

的打印屏幕

下面是 CSS 代码:

#RevenueMTable tbody, #RevenueMTable thead {
display: block; 
}

#RevenueMTable {
    width: 1115px;
    table-layout: fixed !important;
}

#RevenueMTable tbody td:first-child
{
    width: 138px !important;
}

#RevenueMTable tbody td:not(:first-child)
{  
    width: 72px !important;

}

#RevenueMTable tbody
{
   overflow: auto;
   height: 400px;

}

问题是我的第一列的行跨度为 4 行。因此,例如包含 "COST" 的单元格是行标记中的第一个 TD 元素,因此也应用了 138px 的宽度,尽管它应该被视为第二列。

我该如何解决这个问题?

我尝试如下应用列定义宽度,但也不起作用:

 $( '<col style="width:138px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"> <col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px"><col style="width:72px">').insertBefore( $("#RevenueMTable thead") )
  #RevenueMTable tbody td:nth-child(2)
  {  
      width: 72px !important;
  }

您的 TD 元素已经 类。您可以直接使用这些来定位列。我更改了规则的顺序,因此它们将根据具体情况正确覆盖。

#RevenueMTable tbody td
{  
    width: 72px !important;

}

#RevenueMTable tbody td.column0 {
    width: 138px !important;
}