mistaya123 — 2011-02-07T01:26:01-05:00 — #1
I was wondering how to make something (for example, an image) automatically position in the center of a div, vertically as well as horizontally?
For horizontal, it is "margin:0 auto;"
How to position automatically in the middle, vertically? If the outer div, in which the image is to be placed, has variable height and width.
ralphm — 2011-02-07T09:21:25-05:00 — #2
This article by Paul O'Brien shows how to do it with a fixed height:
At the bottom of the page, he links to an example where height is not fixed:
paulob — 2011-02-07T12:37:19-05:00 — #3
Here's another method that vertically aligns the horizontal content in relation to each other (but not necessarily with the parent outer as in the example that Ralph has linked to).
Vertical centring is awkward if you want older browser support. Modern browsers (IE8+, Firefox, Safari etc..) can all use the display:table properties and can vertically center quite easily.
mistaya123 — 2011-03-22T07:39:42-04:00 — #4
Thank you for your help guys.