Borders not shown in Firefox with border-collapse on table, position: relative on tbody, or background-color on cell

后端 未结 7 2015
余生分开走
余生分开走 2020-11-30 01:58

Consider the following HTML:

<
相关标签:
7条回答
  • 2020-11-30 02:36

    Just ran into this issue and came to a css only solution: just add background-clip: padding-box to your td element.

    See this article for more information: https://developer.mozilla.org/en-US/docs/CSS/background-clip

    0 讨论(0)
  • 2020-11-30 02:36

    The best way to solve this issue is to do something like this.

    Note the position: relative property in the "thead" and the "tbody' elements, those are important. So are the border-collapse and background-clip properties. Works with background-color on all and alternating rows.

    table {
      width: 100% !important;
      border-spacing: 0;
      border-collapse: unset !important;
    
      thead {
        position: relative;
        left: -1px;
        top: -1px;
    
        tr {
          th {
            background-clip: padding-box;
            border-top: 1px solid #737373!important;
            border-left: 1px solid #737373!important;
            border-right: none !important;
            border-bottom: none !important;
    
            &:last-child {
              border-right: 1px solid #737373!important;
            }
          }
        }
      }
    
      tbody {
        position: relative;
        left: -1px;
        top: -1px;
    
        tr {
          &:last-child {
            td {
              border-bottom: 1px solid #737373!important;
            }
          }
    
          td {
            background-clip: padding-box;
            border-top: 1px solid #737373!important;
            border-left: 1px solid #737373!important;
            border-right: none !important;
            border-bottom: none !important;
    
            &:last-child {
              border-right: 1px solid #737373!important;
            }
          }
        }
      }
    }
    
    0 讨论(0)
  • 2020-11-30 02:38

    Adding another solution for this (old) issue: This happened to me today, because I have a somewhat complicated table with multiple tbody. The only issue was actually that I had an opened tbody tag that was not closed. I deleted that tag and the borders re-appeared, without needing to change anything in my CSS. To clarify, my structure was something like:

    <table>
      <thead>
        <tr><th>Col1</th><th>Col2</th></tr>
      </thead>
      <tbody>
      <tbody>
        <tr><td>Val1</td><td>Val2</td></tr>
        <tr><td>Val3</td><td>Val4</td></tr>
      </tbody>
    </table>

    0 讨论(0)
  • 2020-11-30 02:44

    This is a bug in firefox and hopefully they fix it soon. But in the mean time I was able to fix this issue for me by setting my td cells to position: static. Hopefully that will help someone else.

    td {
        position: static;
    }    
    
    0 讨论(0)
  • 2020-11-30 02:48

    Just to put all in one place.

    The problem is produced when you have a cell with position relative inside a table with collapsed borders (as Boris indicated and filled in the bug https://bugzilla.mozilla.org/show_bug.cgi?id=688556)

    This can be easily solved using CSS as indicated by user2342963 (Adding background-clip: padding-box to the cell).

    You can see the problem (with Firefox) and the fix here: http://jsfiddle.net/ramiro_conductiva/XgeAS/

    table {border-spacing: 0px;}
    td {border: 1px solid blue; background-color: yellow; padding: 5px;}
    td.cellRelative {position: relative;}
    td.cellRelativeFix {background-clip: padding-box;}
    table.tableSeparate {border-collapse: separate;}
    table.tableCollapse {border-collapse: collapse;}
    
    <table class="tableSeparate">
        <tbody>
            <tr>
                <td class="cellRelative">position: relative</td>
                <td>position: static</td>
            </tr>
        </tbody>
    </table>
    <table class="tableCollapse">
        <tbody>
            <tr>
                <td class="cellRelative">position: relative</td>
                <td>position: static</td>
            </tr>
        </tbody>
    </table>
    <table class="tableCollapse">
        <tbody>
            <tr>
                <td class="cellRelative cellRelativeFix">position: relative</td>
                <td>position: static</td>
            </tr>
        </tbody>
    </table>
    
    0 讨论(0)
  • 2020-11-30 02:49

    This looks like a Firefox bug to me. The backgrounds are painting over the borders; you can see it if you use a translucent background color.

    I filed https://bugzilla.mozilla.org/show_bug.cgi?id=688556

    0 讨论(0)
提交回复
热议问题