Why is Firefox missing the border on some HTML tables

前端 未结 9 1774
我在风中等你
我在风中等你 2021-02-04 00:05

I am using Firefox 3.5.7 and I have the same CSS used in multiple HTML tables, but there are some examples where parts of the borders are not shown.

What makes no sens

9条回答
  •  长情又很酷
    2021-02-04 00:35

    I found a similar problem when zoomed out in Firefox on an application I am working on.

    The main cause was having the CSS border-collapse property set to collapse.

    Changing it to separate instead fixed the problem. However, that meant I did have to rethink the way borders are applied to various parts of the table, because otherwise your borders will appear to double in thickness. I ended up having to use jQuery to give a special "last" class to the last td or th in each tr, and to the last tr in the table. My query was something like:

    $('table tr > th:last-child, table > tbody > tr > td:last-child, table > tbody > tr:last-child').addClass('last');
    

    My CSS rules were similar that:

    table
    {
        border-collapse: separate !important;
    }
    
    table tr, table th, table td
    {
        border-right-width: 0;
        border-bottom-width: 0;
        border-left: 1px solid black;
        border-top: 1px solid black;
    }
    
    table td.last, table th.last 
    {
        border-right: 1px solid black;
    }
    
    table tr.last td
    {
        border-bottom: 1px solid black;
    }
    
    table
    {
        border: 0;
    }
    

    I did end up using browser targeting so that I only applied these rules to Firefox users, but it may work for all browsers, I haven't tested.

提交回复
热议问题