Center DIV with Dynamic Height


/ Published in: CSS
Save to your folder(s)



Copy this code and paste it in your HTML
  1. CSS:
  2.  
  3. * { margin: 0; padding: 0; }
  4. #page{display:table;overflow:hidden;margin:0px auto;}
  5. *:first-child+html #page {position:relative;}/*ie7*/
  6. * html #page{position:relative;}/*ie6*/
  7.  
  8. #content_container{display:table-cell;vertical-align: middle;}
  9. *:first-child+html #content_container{position:absolute;top:50%;}/*ie7*/
  10. * html #content_container{position:absolute;top:50%;}/*ie6*/
  11.  
  12. *:first-child+html #content{position:relative;top:-50%;}/*ie7*/
  13. * html #content{position:relative;top:-50%;}/*ie6*/
  14.  
  15. html,body{height:100%;}
  16. #page{height:100%;width:465px;}
  17.  
  18. HTML:
  19.  
  20. <div id="page">
  21. <div id="content_container">
  22. <div id="content">
  23. <p>your content</p>
  24. </div>
  25. </div>
  26. </div>

URL: http://css-tricks.com/snippets/css/center-div-with-dynamic-height/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.