Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 237
avernet Avatar asked Jan 10 '09 03:01

avernet


2 Answers

The solution I found consists in adding a top/left to move the rendering off-screen, which shields us against IE bugs of this sort. In the above example, this means that you would define the CSS for the hide class as:

.hide {
    visibility: hidden;
    position: absolute;
    top: -10000px;
    left: -10000px;
}

More on: Workaround for table borders showing through on IE

like image 80
avernet Avatar answered Nov 08 '22 21:11

avernet


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

like image 5
Rex the Strange Avatar answered Nov 08 '22 19:11

Rex the Strange