Display the image in the center of the page

前端 未结 3 943
一生所求
一生所求 2020-12-31 17:58

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 :

im         


        
相关标签:
3条回答
  • 2020-12-31 18:43

    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 */
    }
    
    0 讨论(0)
  • 2020-12-31 18:55

    See W3C

    IMG.displayed {
        display: block;
        margin-left: auto;
        margin-right: auto 
    }
    
    <IMG class="displayed" src="..." alt="...">
    
    0 讨论(0)
  • 2020-12-31 18:59

    Or you can use background: url(center_image) no-repeat center;


    working example: http://jsfiddle.net/DT4hL/

    0 讨论(0)
提交回复
热议问题