views:

1049

answers:

3

I have the following CSS class:

.hidden {
    visibility: hidden;
    position: absolute;
}

I have div with that class on it. If I remove the class, the div doesn't show. But the second time I "remove it", the div shows. Any idea why? See a stand-alone example using YUI for this:

http://avernet.googlepages.com/ie-visibility.html (code also available on Pastie)

Note: I can't use display: none in my case (which otherwise would have worked).

A: 

It looks like it has to do with the "position:absolute;". If you remove that line it works, or if you add

div { position:absolute; }

it works as well.

David
David: yes, it works without the position:absolute, but if you don't put the position:absolute, then the content you hide still takes space on the page, which is not what I want.
Alessandro Vernet
Why can't you use "display:none;" then? The only reason to use "visiblity:hidden" is to keep the space on the page.
David
@David, some "widgets" you have in the div don't initialize correctly if the div is hidden with display: none. Instead, using visibility: hidden and making sure the div is rendered off-screen solves the problem. See for instance what the YUI guys have to say here: http://developer.yahoo.com/yui/examples/editor/switch_editor.html (on that page, search for "It is not recommended").
Alessandro Vernet
+1  A: 

do you mean display:none instead of visibility:hidden?

cheers

Marko
No, I need to use visibility: hidden in this case. And it doesn't work. Hence the problem.
Alessandro Vernet
When you use position:absolute you take the div out of the document flow, so there is no difference between display:none and visibility:hidden as far as I can see.
jeroen
A: 

Using the nudge technique for IE does the trick. I added more information on this wiki: look for the heading Cell content remains hidden on IE .

And here is the implementation for the nudge that we are using in the Orbeon Forms code:

/**
 * Nudge element after a short delay for IE6/7 to force IE to "do the right thing".
 */
nudgeAferDelay: function(element) {
    if (YAHOO.env.ua.ie != 0 && YAHOO.env.ua.ie <= 7) {
        window.setTimeout(function() {
            element.className = element.className;
        }, ORBEON.util.Utils.getProperty(INTERNAL_SHORT_DELAY_PROPERTY));
    }
}
Alessandro Vernet