window.onload = function(){ var xx = document.documentElement.clientHeight; // 470为要垂直居中的div的高度 he = (xx-470)/2; console.log(he); document.getElementsByClassName('weixin_public')[0].style.marginTop = he + 'px'; } 通过以上的js控制即可达到垂直居中的效果…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ…