<div id="wr">
<div id="unknownWidthAndHeight">should be centered on both sides</div>
</div>
#wr {
display:table-cell;
width:400px;
height:100px;
border:1px solid red;
margin:50px;
vertical-align:middle;
}
#unknownWidthAndHeight{
display:table;
height:30px;
margin:auto;
border:1px solid blue;
}
Here is fiddle example:
http://jsfiddle.net/gdTGZ/2/
Need such support for IE7 without display:table etc. and without <table> usage.
1/ If you want to vertical center on IE7 try this technique using three divs :
http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
Ps : You’ll always need to set the container height.
2/ The element that you want to horizontal center must have a
widthandmargin:0 auto;otherwise you can trytext-align:center