tags:

views:

61

answers:

3

I have a image -- a loading image.

I want that image to be displayed in the center on the page. How can i do that?

The code that i wrote is :

img.loading
 {
  position:absolute;
  left:0px;
  top:0px;
  z-index:1;
 }

How can i make this image always be displayed in the center of the page??

Zeeshan

+2  A: 

See W3C

IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto 
}

<IMG class="displayed" src="..." alt="...">
Chase Seibert
This will center the image horizontally but not vertically.
Ken Browning
The link covers that, but it's not ideal. "CSS level 2 doesn't have a property for centering things vertically. There will probably be one in CSS level 3."
Chase Seibert
+1  A: 

Found this: How to Center an Image Perfectly in CSS, might help.

#img
{
    position:absolute;
    width:592px; /*image width */
    height:512px; /*image height */
    left:50%; 
    top:50%;
    margin-left:-296px; /*image width/2 */
    margin-top:-256px; /*image height/2 */
}
CD