Css – IE CSS bug: table border showing div with visibility: hidden, position: absolute

cssinternet-explorer

The issue

I have a <div> on a page which is initially hidden with a visibility: hidden; position: absolute. The issue is that if a <div> hidden this way contains a table which uses border-collapse: collapse and has a border set on it cells, that border still shows "through" the hidden <div> on IE.

Try this for yourself by running the code below on IE6 or IE7. You should get a white page, but instead you will see:

alt text http://img.skitch.com/20090110-enuxpb5aduqceush46dyuf4wk7.png

Possible workaround

Since this is happening on IE and not on other browsers, I assume that this is an IE bug. One workaround is to add the following code which will override the border:

.hide table tr td {
    border: none;
}

I am wondering:

  • Is this a known IE bug?
  • Is there a more elegant solution/workaround?

The code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <style type="text/css">

            /* Style for tables */
            .table tr td {
                border: 1px solid gray;
            }
            .table {
                border-collapse: collapse;
            }

            /* Class used to hide a section */
            .hide {
                visibility: hidden;
                position: absolute;
            }

        </style>
    </head>
    <body>
        <div class="hide">
            <table class="table">
                <tr>
                    <td>Gaga</td>
                </tr>
            </table>
        </div>
    </body>
</html>

Best Solution

This is a IE bug. Firefox doesn't recognize "border-collapse" using "border-spacing" instead which does not cause this problem. The solution of using "display:none" works, but there's another possibility. If the visibility property is set using Javascript then the border is hidden as well (as expected).

Related Question