让块级元素水平垂直居中

			function fun(){
                   var wWidth = null,
                     wHeight = null; if(window.innerHeight && window.innerWidth){ wHeight = window.innerHeight;
                        wWidth = window.innerWidth; }else if((document.body) && (document.body.clientHeight) && (document.body.clientWidth)){
                        wWidth = window.clientWidth; wHeight = window.clientHeight; }
                   var boxWidth = document.getElementById("box").clientWidth; var boxHeight = document.getElementById("box").clientHeight;
                   box.style.marginLeft = (wWidth - boxWidth)/2 + "px"; box.style.marginTop = (wHeight - boxHeight)/2 + "px"; }
              window.onload = window.onresize = function(){fun()}
原文地址:https://www.cnblogs.com/laoniaofly/p/6031363.html