Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Firefox not render border of table with empty tbody?

Firefox does not render table cell borders correctly when a table has an empty tbody.

But if you use the pseudo selector tbody:empty {display:none;} to hide the tbody element, everything is rendered as expected.

jsfiddle

table {
    border-collapse: collapse;
}
th,
td {
    border: 1px solid #000;
}

.fixed tbody:empty {
    display: none;
}
<table class="broken">
    <thead>
        <tr>
            <th>1</th>
            <td>2</td>
            <td>3</td>
        </tr>
    </thead>
    <tbody></tbody>
    <tfoot>
        <tr>
            <th>1</th>
            <td>2</td>
            <td>3</td>
        </tr>
    </tfoot>
</table>

<hr />

<table class="fixed">
    <thead>
        <tr>
            <th>1</th>
            <td>2</td>
            <td>3</td>
        </tr>
    </thead>
    <tbody></tbody>
    <tfoot>
        <tr>
            <th>1</th>
            <td>2</td>
            <td>3</td>
        </tr>
    </tfoot>
</table>
like image 617
zeropaper Avatar asked Oct 16 '15 10:10

zeropaper


People also ask

Why does my HTML table have no borders?

If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.

How do I make a table border transparent?

Right-click the table, and then click Format Table. In the Format Table dialog box, under Fill, move the Transparency slider to get the percentage of transparency you want.

Does border-collapse only work on tables?

The border-collapse property is for use on <table> elements (or elements made to behave like a table through display: table or display: inline-table ).

How do you specify a table border?

To create table border in HTML, the border attribute was used. But the introduction of HTML5, deprecated the border tag. Create table border using the CSS property border. Set table border as well as border for <th> and <td>.


1 Answers

It most likely belongs to Bug 409254 and Bug 217769 on Firefox.

Side note: Although an empty tbody is valid in HTML 5, but the number of the cells in each row group should be matched (except using colspan) in one table.

A workaround would be drawing the borders separately on both the table and cell elements.

table {
    border-collapse: separate; /*changed from collapse*/
    border-spacing: 0;
    border: 1px solid;
    border-width: 0 0 1px 1px; /*draw bottom and left borders*/
}
th,
td {
    border: 1px solid;
    border-width: 1px 1px 0 0; /*draw top and right borders*/
}

jsfiddle

like image 72
Stickers Avatar answered Oct 30 '22 08:10

Stickers