【问题标题】:Table with borders collapsed - right border overflows bottom边框折叠的表格 - 右边框溢出底部
【发布时间】:2018-06-24 01:27:17
【问题描述】:

问题很简单:我怎样才能让橙色底部边框越过蓝色边框,而不是下方?

* {
  box-sizing: border-box;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

td {
  border-right: 6px solid blue;
  border-bottom: 6px solid orange;
}
<table>
    <tr><td>aaa</td><td>aaa</td></tr>
    <tr><td>aaa</td><td>aaa</td></tr>
</table>

我在下面的答案中提供了一种可能的解决方案,但它相当老套,我很好奇是否有更漂亮的解决方案?


编辑:我知道这是默认行为而不是错误,根据 this answer,我只想覆盖它。

【问题讨论】:

    标签: html css border css-tables


    【解决方案1】:

    我们提出的解决方案是使用:after 伪元素而不是边框​​。它有效,但并不像我们希望的那样漂亮:

    * {
      box-sizing: border-box;
    }
    
    table {
      border-collapse: collapse;
      border-spacing: 0;
    }
    
    td:after {
      content: '\00a0';
      background: orange;
      position: absolute;
      right: 0;
      top: 0;
      bottom: 0;
      width: 6px;
      display: inline-block;
    }
    
    td {
      position: relative;
      background: white;
      padding-right: 6px;
      
      border-bottom: 6px solid blue;
    }
    <table>
        <tr><td>aaa</td><td>aaa</td></tr>
        <tr><td>aaa</td><td>aaa</td></tr>
    </table>

    我不知道如何仅通过边框来实现这一点。

    【讨论】:

    • 接受,因为没有出现其他答案。不过,仍然可以接受其他答案。