Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the image in the center of the page

Tags:

css

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 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?

like image 849
Zeeshan Rang Avatar asked Aug 03 '09 20:08

Zeeshan Rang


2 Answers

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 */
}
like image 169
CD.. Avatar answered Sep 30 '22 18:09

CD..


See W3C

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

<IMG class="displayed" src="..." alt="...">
like image 30
Chase Seibert Avatar answered Sep 30 '22 18:09

Chase Seibert