网页垂直居中

<!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-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.kkkk {
background-color: #CCCCCC;
 
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
 
<body>
 
  <table width="100%" border="1" cellpadding="0" cellspacing="0" class="kkkk" id="mainDiv">
    <tr>
      <td align="center" valign="middle"><table width="200" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
  </table>
 
<script type="text/javascript" language="javascript">
function OnResize()
{
window.document.getElementByIdx("mainDiv").style.height=document.documentElement.clientHeight + "px";
}
OnResize();
window.onresize = OnResize;
</script>
</body>
</html>
 
原文地址:https://www.cnblogs.com/dcrenl/p/4041167.html