Display image in the center of the page

I have an image - a loading image.

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

The code I wrote is:

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

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

+5
source share
3 answers

The following was discovered: How to efficiently center an image in CSS .

#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 */
}
+20
source

See W3C

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

<IMG class="displayed" src="..." alt="...">
+6
source

background: url(center_image) no-repeat center;


: http://jsfiddle.net/DT4hL/

+4

All Articles