前段时间有写过这个话题,今天在来补充一下,以下是支持IE6,IE7和Firefox垂直居中代码。
<!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=gb2312" />
<title>div层在html页面中垂直居中</title>
</head>
<style>
body {padding: 0; margin: 0;}
body,html{height: 100%;}
#outer {
height: 100%;
overflow: hidden;
position: relative;
width: 100%;
background:#000;
display:table;
}
#outer[id] {
display: table;
position: static;
*position:relative;
_position: static;
}
#middle {
position: absolute;
top: 50%;
left: 0;
vertical-align:middle;
display:table-cell;
width:100%;
*vertical-align:middle;
*display:table-cell;
*width:100%;
_vertical-align:;
_display:;
_width:;
}
#middle[id] {
display: table-cell;
vertical-align: middle;
position: static;
top:50%;
left:0;
width:100%;
*position:absolute;
_position: ;
}
#inner {
position: relative;
top: -50%;
margin: 0 auto;
text-align:center;
}
#content{
width:500px;
height:400px;
border:1px solid red;
background:#EEE;
margin: 0 auto;
text-align:left;
}
</style>
<body>
<div id="outer">
<div id="middle">
<div id="inner">
<div id="content">div层在html页面中垂直居中div层在html页面中垂直居中div层在html页面中垂直居中div层在 html页面中垂直居中div层在html页面中垂直居中</div>
</div>
</div>
</div>
</body>
</html>