Skip to content

Instantly share code, notes, and snippets.

@jackilyn
Created January 6, 2012 23:01
Show Gist options
  • Save jackilyn/1572851 to your computer and use it in GitHub Desktop.
Save jackilyn/1572851 to your computer and use it in GitHub Desktop.
Center a <div> with Dynamic Height
<style>
* {margin: 0; padding: 0;}
#page {display:table; overflow:hidden; margin:0px auto;}
*:first-child+html #page {position:relative;} /*ie7*/
* html #page {position:relative;} /*ie6*/
#content_container {display:table-cell; vertical-align: middle;}
*:first-child+html #content_container {position:absolute; top:50%;} /*ie7*/
* html #content_container {position:absolute; top:50%;} /*ie6*/
*:first-child+html #content {position:relative;top:-50%;} /*ie7*/
* html #content {position:relative;top:-50%;} /*ie6*/
html, body {height:100%;}
#page {height:100%; width:465px;}
</style>
<div id="page">
<div id="content_container">
<div id="content">
<p>Your content.</p>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment