1. 程式人生 > >html內容垂直、水平居中

html內容垂直、水平居中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<title> New Document </title> 
<style>
*{
padding: 0;
margin: 0;
}
html,body{
height: 100%;
}
#outer{
height: 100%;
width: 100%;
display: table;
*position: relative;
*overflow: hidden;
}
#middle{
display: table-cell;
vertical-align: middle;
*position: absolute;
*top: 50%;
}
#inner {
width: 400px;
margin: 0 auto;
*position: relative;
*top: -50%;
}
</style> 
</head> 
<body> 
<div id="outer">
  <div id="middle">
      <div id="inner" style="background: red;height: 500px;">
          <p>asdfasdf</p>
          <p>asdf</p>
      </div>
  </div>
</div>
</body> 
</html>