-2

Possible Duplicate:
vertical alignment of elements in a div

I have div tag, in him i have img tag, div tags sizes is static: 200x200, img sizes is always less than 200px, but how exactly, I dont know beforehand. I want img will be alwasy center of the div tag, in horizontal I make, but how to make this as vertikal ?

   <div style="width: 200px; height: 200px; background-color: #090; text-align: center; ">
        <img src="pic.jpg">
    </div>
Community
  • 1
  • 1

1 Answers1

3

Look at this JSFIDDLE

You can use the CSS calc() function to vertically center an image inside the div:

position: relative;
top: -webkit-calc(50% - []px )    /* [] = half the image height) */;  
top: calc(50% - []px)    /* [] = half the image height) */; 
amiregelz
  • 1,718
  • 7
  • 20
  • 36