Search code examples
cssvertical-alignment

Completely center an image?


I have a div and an image within the div. The image size will vary.

I want it to be centered horizontally and vertically. Css verticle align does't seem to work.

Any tricks? I can use php, css or Jquery


Solution

  • I don't know how you use it, so probably my solution won't fit.

    When you implement the image as a 'background-image' within the div you can easily center it with 'background-position':

    #div {
    background-image: url(./image.png);
    background-position: center center;
    }