I am trying to vertically and horizontally center a container, and the content inside using CSS.
The markup looks like this:
<div id="container">
<img src="..someimage.jpg">
<img src="..someverticaldivider">
<form action="action.php">
<input type="text">
.... (other inputs)
</form>
</div>
I need the end result to look like this:

So far, my css looks like this:
#content{
position:absolute;
width: 900px;
left:50%;
top:50%;
height:300px;
margin-top:-150px;
margin-left: -450px;
}
That works fine and if I add a border to #content, I can easily see that it is indeed centered horizontally and vertically.
The problem I am facing is that I do not know the size of the content inside #content. I need to be able to align those elements 2 images and 1 form horizontally and vertically. I have checked out this site for vertically centering, but the problem is that I do not know the size of my content, and the content is not only text.
What is the best way to do this with support for older browsers (IE7 and up)?
edit 1
And here is the the final result of the jury
This centers also the content inside the box vertically (image, vertical ruler, form)
http://jsfiddle.net/HerrSerker/TuPvF/13/
I’m trying to give an authoritative answer to this.
Maybe this won’t work in mobile browsing (smart phones, iPad etc.). Could anyone check?
Use
display: tableanddisplay: table-cellin modern browsers which support them to make use of thevertical-alignwhich works with them.Use positioning with relative measures in some old IE browsers
http://jsfiddle.net/HerrSerker/TuPvF/