Vertically And Horizonatally center main wrap div
Possible Duplicate:
How to center DIV in DIV?
Now i try
<html>
<head>
<title>?????????????????</title>
<style type="text/css">
body
{
margin-left: auto;
margin-right:auto;
}
#wrap
{
background: black;
margin-left: auto;
margin-right:auto;
height:450px;
width:450px;
position:absolute;
top:50%;
right:50%;
left:50%;
margin-top:-225px;
}
</style>
</head>
<body>
<div id="wrap">
Hello
</div>
</body>
</html>
?????
尝试这个:
<html>
<head>
<title>?????????????????</title>
<style type="text/css">
#content
{
background: black;
margin: -225px;
height: 450px;
width: 450px;
}
#wrap
{
height: 0px;
width: 0px;
position:absolute;
top:50%;
left:50%;
}
</style>
</head>
<body>
<div id="wrap">
<div id="content">
Hello
</div>
</div>
</body>
</html>
vertical-align
does not work the way most beginners expect it to work.
Here is one tutorial explaining the situation. It sounds like you want Method 1.
<html>
<head>
<title>?????????????????</title>
<style type="text/css">
.ui-container
{
background: red;
}
.ui-wrapper
{
margin: auto;
background: black;
height:450px;
width:450px;
color: red;
}
</style>
</head>
<body>
<div class="ui-container">
<div class="ui-wrapper">
<p>Hello</p>
</div>
</div>
</body>
</html>
链接地址: http://www.djcxy.com/p/13208.html
上一篇: 我如何居中<div>?
下一篇: 垂直和水平中心主包装div