Forum Moderators: not2easy
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.central {
width:200px;
height:200px;
background:red;
border:1px solid #000;
position:fixed;
left:0;
right:0;
margin:auto;
top:25px;
text-align:center;
}
*+html .central{/* ie7 fix*/
left:50%;
right:auto;
margin-left:-100px;
}
/* IE6 doesn't understand position:fixed*/
</style>
</head>
<body>
<div class="central">Test</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html,body{
margin:0;
padding:0;
height:100%;
}
.central {
width:200px;
height:200px;
background:red;
border:1px solid #000;
margin:auto;
text-align:center;
clear:both;
}
.push{
float:left;
width:100%;
height:50%;
margin-top:-100px;
clear:both
}
</style>
</head>
<body>
<div class="push"></div>
<div class="central">Test</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html,body{
height:100%;
margin:0;
padding:0
}
.central {
width:200px;
height:200px;
background:red;
border:1px solid #000;
position:fixed;
left:0;
right:0;
margin:auto;
top:50%;
margin-top:-100px;/* half height of element */
text-align:center;
}
*+html .central {/* ie7 fix*/
left:50%;
right:auto;
margin-left:-100px;
}
/* IE6 doesn't understand position:fixed*/
</style>
</head>
<body>
<div class="central">Test</div>
</body>
</html>
but vertically, it is centered by the upper left hand corner of the div, not the center of the div. "margin: auto auto;" does not work vertically.