跨浏览器自动垂直/水平居中(与Chrome和Forms兼容)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨浏览器自动垂直/水平居中(与Chrome和Forms兼容)相关的知识,希望对你有一定的参考价值。
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.
<style type="text/css"> 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>
以上是关于跨浏览器自动垂直/水平居中(与Chrome和Forms兼容)的主要内容,如果未能解决你的问题,请参考以下文章
在 CSS 中以圆形垂直和水平居中文本(如 iphone 通知徽章)