a collection of front-end idea's, tutorials and snippets


Vertical align an image in the center with CSS

I want to center an image vertically.

I don’t know the image size.

I don’t want to use javascript.

I don’t care about IE browsers lower than IE9.


Then this is what you can use. Centering an image, width and height, CSS only:

.container { position: relative; } 
.container img { position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; }

Another method, IE7+ proof, with fixed height: Absolute Center (Vertical & Horizontal) an Image

Leave a Reply

Theme by Anders Norén