Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsed table borders in firefox sometimes missing

The HTML spec allows for multiple tbody elements in tables. I have a case like that where Firefox doesn't seem to want to handle collapsed borders.

http://jsfiddle.net/hunvjrp4/

The borders on the second table display properly in Chrome 37, but don't do so hot in Firefox 33 or Internet Explorer 11.

Basically, it looks like if there is any tbody that contains (only?) hidden content, then it fails to render the borders correctly for the whole table.

Is there a workaround to get the borders to draw correctly?

I've tried not collapsing the borders, which seems to work, but leaves this particular table looking different than other tables on the site.

Code sample for fiddle linked above:

With multiple `tbody` elements:
<table class="mainContent">
    <thead><tr><th>hi</th><th>there</th></tr></thead>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>   
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>   
</table>
<br />
<br />

If any of the tbody elements contain a single display: none row then things go awry:

<table class="mainContent">
    <thead><tr><th>hi</th><th>there</th></tr></thead>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>   
    <tbody><tr class="hide"><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>
    <tbody><tr><td>hi</td><td>there</td></tr></tbody>   
</table>

And the styles:

table {
    border-collapse: collapse;
}
table tr td {
    border: solid 1px #ccc;
    padding: 4px;
}
.hide {
    display: none;
}
like image 652
jinglesthula Avatar asked Nov 04 '14 20:11

jinglesthula


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 enable table borders?

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>.

Are table borders deprecated?

W3C DOM 2 HTML Specification HTMLTableElement. border. This attribute is deprecated in HTML 4.0.

What does table border-collapse do?

The border-collapse property sets whether table borders should collapse into a single border or be separated as in standard HTML.


1 Answers

It's a very strange behaviour, possibly a Bug in my opinion.

I tried to solve it with some workaround and first succesful one was to apply .hide class to tbody tag instead than on TR, but then I thought that probably you have some reason to apply it on table row, so I turned to "descendant selector" technique.

Look at this updated example. The only difference is that display:none is applied to TD, while continuing to set .hide class to TR in html.

.hide td {
    display: none;
}
like image 59
Luca Detomi Avatar answered Oct 08 '22 16:10

Luca Detomi