/ Published in: CSS
A way to do 100% DIVs that adjust to content and center themselves both vertically and horizontally automatically. Tested for all browsers at 1920X1080 resolution. The 96% body height fixes Firefox and IE scrollbars that appear without reason and might need to be adjusted for smaller or larger windows.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<style type="text/css"> html,body,form {height:100%;margin:0px;padding:0px;} html{height:100%;} body{height:96%;text-align:center;}/*height 96% fixes scrollbar problems*/ /*remove text-align for left justification*/ form{display:block;}/*chrome & forms*/ #page{display:table;overflow:hidden;margin:0px auto;padding:0px;min-height:100%;} *: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%;left:-50%;}/*ie7*/ * html #content{position:relative;top:-50%;left:-50%;}/*ie6*/ #page{height:100%;width:100%;} </style> <body> <div id="page"> <div id="content_container"> <div id="content"> <!-- centered content here --> </div> </div> </div> </body>