Without IE support, this is pretty easy to achieve with display: table and display: table-cell .
Here is an update to your HTML:
<div id='my_div'> <div class="centered">this is vertically centered</div> </div>
CSS
body, html { height: 100%; } body { margin: 0; padding: 0; border: 1px solid blue; } #my_div { width: 300px; border: 1px solid red; margin-left: auto; margin-right: auto; height: 100%; display: table; overflow: hidden; } .centered { display: table-cell; vertical-align: middle; text-align: center; }
And for preview: http://jsfiddle.net/we8BE/
wsanville
source share