views:

94

answers:

4

Hello all:

I couldn't find a similiar question in the related questions section, so figured I'd try my luck.

I'm designing a page where the load time will noticeably long enough to where a loading icon could appear. Currently I have it set so that the icon displays in the center of the screen, with a translucent overlay over the page until page load is complete. Here's the code that I am using

        <style type="text/css">
    #overLayBackground{
     background-color: rgb(250, 250, 250);
     opacity: 0.7; /* Safari, Opera */
     -moz-opacity:0.25; /* FireFox */
     filter: alpha(opacity=70); /* IE */
     z-index: 200;
     height: 100%;
     width: 100%;
     background-repeat:repeat;
     position:fixed;
     top: 0px;
     left: 0px;
     text-align:center; 
         line-height: 240px; 
    }

    #overLayBackground>img {
        position:absolute; bottom:0; top:0; left:0; right:0; margin:auto;
    }

<div id="overLayBackground">
    <img src="www.example.com/images/loading.gif" title="Image" alt="The image" />
</div>

Now this works as expected in Firefox and Chrome, but IE has the icon showing in the top left hand corner. Is there a way to have it behave as the other browsers and position it in the center of the screen?

Thanks in advance.

+1  A: 

If you use margin:auto for centering, then you shouldn't use absolute positioning for the img.

EDIT: in response to op comment. margin:auto only works for horizontal centering, this is by definition of how margins work. for vertical centering, I have used a different technique in the past, by using top: 50%, and then using negative top margin.

I recommend this alistapart article:

http://www.alistapart.com/articles/holygrail/

and more alistapart goodness here:

http://www.alistapart.com/articles/practicalcss/

Yoni
Thanks for your reply. Tried the following configurations with the following results:position:relative, no margin:auto - both IE and FF have the image centered horizontally, but the image is at the top of the screen instead of centered vertically.no position set, margin:auto - same thing.position:relative, margin:auto - same thing.position:absolute, no margin:auto - both IE and FF have the image in the top left hand corner
canadiancreed
+2  A: 

Your code works in IE8 once you specify a doctype and fix the syntax error (div inside the style tag).

jáquer
Thanks for the reply, and for the catch on the div within style.At the top of the page, the doctype is the following: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> Can what I'm trying to do work with this doctype? (cant' see why not, but you never know)
canadiancreed
Just using the question's code and the doctype, it worked..
Stavros
+1  A: 

Here's a custom one I've used with one of my Custom Cloud Applications: NGEN Preload Screen

View the source for body.onload action...

Feel free to repurpose it at your leisure...

drlouie - louierd
A: 

Found the solution. If you change the #overLayBackground>img line to position:absolute; top:50%; left:50%; it works in both IE and FF centering the image vertically and horizontally. Thanks to all that responded.

canadiancreed
This doesn't seem to solve the problem. Could you post a complete solution?
Stavros