I think this question has been asked many a times but I've been searching the web for a whole day now and cannot find a single good solution. I want to centre an image inside a div so that it looks like a frame. I have images of different sizes, some are portrait, some landscape. I want them to be centered horizontally and vertically and that it does not overflow the container if the size is larger. Now I've read about div vs table designs but seriously, right now I just want the job done, so any solution would be greatly appreciated.
Asked
Active
Viewed 1,034 times
1
-
1http://www.w3.org/Style/Examples/007/center.en.html#vertical – s3mre8 Jun 28 '12 at 06:00
2 Answers
3
You can achieve it by clicking the demo link below:
DEMO http://jsfiddle.net/rathoreahsan/99BXT/
NOTE:
Cons: By using
display:table-cellwill not work below Internet Explorer 8 browsers, rest of browsers will except it. Pros: It will work also by using fixed width and fixed height.Pros: By using
display:blockwill work on all browsers. Cons It will not work by using fixed width and fixed height. But you may manage it with samepaddingfor (top, right, bottom, left) as mentioned in this demo
Ahsan Rathod
- 5,465
- 2
- 21
- 25