CSS: 导致边框消失的 TD 背景颜色

CSS: TD background color causing borders to disappear

我有一个动态创建的大型 HTML table。 table 具有标准结构,包括。 colgrouptheadtbody 以及以下样式。

到目前为止,一切都按预期工作,但是当我将 class "bgGrey" 添加到一列中的 TD 时(见下文),以便为该列中的单元格提供背景颜色(仅在一列上需要)然后 该列的所有边框在 IE11 中消失,除了左边框,并且 :hover::before 样式不起作用Chrome(版本 43)中的更多内容。
不添加 class "bgGrey" 我在两种浏览器中都没有问题。

似乎是背景颜色与边框重叠造成的。

我的CSS(相关部分):

#myTable, #myTable tbody, #myTable thead, #myTable tr {
    width: 100%;
}
#myTable, #myTable th, #myTable td {
    border: 1px solid #000;
    border-collapse: collapse;
    margin: 0;
    padding: 4px;
    position: relative;
}
#myTable {
    font-size: 14px;
    table-layout: fixed;
}
#myTable th.editable:hover::before, #myTable td.editable:hover::before {
    border: 1px solid blue;
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: -1;
}
#myTable .th1 {
    padding: 2px;
}
#myTable .th2 {
    font-weight: normal;
}

.bgGrey {
    background-color: #e6e6e6;
}

我的HTML(例子TR):

<tr>
    // ...
    <td class="editable"><div contenteditable="true"></div></td>
    <td class="bgGrey editable txtCenter"><div contenteditable="true"></div></td>
    <td class="editable txtRight"><div contenteditable="true"></div></td>
    // ...
</tr>

请从 #myTable td 中删除 border-collapse: collapse;,这会导致边框消失。避免给 td.

改为这样添加:

#myTable, #myTable th, #myTable td {
    border: 1px solid #000;
    border-collapse: collapse;
    margin: 0;
    padding: 4px;
    position: relative; //REMOVE THIS
}

另外,您能否尝试从 CSS 中删除?

我自己刚遇到这个问题,但我不喜欢这里提供的解决方案,所以我一直在谷歌搜索。我找到了这个答案:

在这里,对 table 单元格的简单添加修复了边框:

table td {
  border: 1px solid #000;
  border-collapse: collapse;
  margin: 0;
  padding: 4px;
  position: relative;
  background-clip: padding-box; /* Add this line */
}

Caniuse

检查浏览器支持

属性 的解释可以在 Standardista

找到