css - 当 colspan 设置在下面的 td 行时,单个 th 的边界扩展到相邻的 th

标签 css google-chrome html-table

具有以下html代码:

<table>
<tr><th>First</th><th class='second'>Second</th><th class='third'>Third</th><th>Fourth</th></tr>
<tr><td>Mike</td><td colspan=2 >John</td><td>Paul</td></tr>
</table>​

以及以下 CSS:

table {
    border-collapse: collapse;
}

td, th {
border: 1px black solid;
}

td {
    border-top: none;
}
th {
    border-bottom: none;
}
th.second {
    border-bottom: 3px green solid;
}
th.third {
}

我希望结果是一张表格在第二个单元格下方有 3px 实线绿线。 而不是在 Chrome 中,我在第二个和第三个单元格下方都有实心绿色边框。

在 firefox 中,结果与预期的一样。这是浏览器错误,还是我的代码不合法​​?

您可以在 http://jsfiddle.net/tt6aP/3/ 查看示例

PS:尝试设置

th.third {
    border-bottom: 2px solid red;
}

然后尝试将其提高到 3px。这更奇怪。

截图

预期: Table as seen in firefox

Chrome : Table as seen in chrome

火狐: Table as seen in firefox

最佳答案

嗯,我不知道这是不是一个错误,但是当我遇到这个 问题,我想出了一个简单的解决方法:插入一个额外的行/列 您要应用边框样式的位置。

<table>
    <tr>
        <th>Ano</th>
        <th class='first'>First</th>
        <th class='second'>Second</th>
        <th class='third'>Third</th>
    </tr>
    <tr class='hack'>
        <td></td>
        <td></td>
        <td></td>
        <td></td>        
    </tr>
    <tr>
        <td>Mike</td>
        <td colspan=2 >John</td>
        <td>Paul</td>
    </tr>
</table>

这是CSS:

table {
    border-collapse: collapse;
}
tr.hack > td {
    height:0px;
}
td, th {
    border: 1px black solid;
}
tr.hack > td, td {
    border-top: none;
}
tr.hack > td, th {
    border-bottom: none;
}
th.first {
    border-bottom: 3px green solid;
}
th.second {
}
th.third {
}

我在 chrome 上测试过 over here

关于css - 当 colspan 设置在下面的 td 行时,单个 th 的边界扩展到相邻的 th,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12448155/

相关文章:

html - CSS:如何更改特定禁用字段的字体颜色?

HTML Bootstrap 页脚未按应有的方式响应。它没有粘在底部,也没有像我编程的那样显示 100% 的宽度

javascript - 使用 iScroll 始终显示滚动条

html - block 级元素相互重叠

javascript - 在 Chrome 扩展程序中使用 PAC 文件重定向 HTTPS 请求似乎失败

c++ - 将 IAccessible 与 Google Chrome 一起使用会返回不完整的树

css 子选择器不适用于线程中的元素

jquery - 为tinyMCE添加自定义表格样式

macos - Chrome 中的 SVG strip

html - CSS 表格单元格等宽