我想在中间有一个文本框。我尝试使用下面的代码。但它并没有把它放在中心位置。输出的图像也可以在下面找到。请通过指出代码中的错误来帮助我。
<html>
<head>
<style>
#form
{
margin-top:40%;
margin-left:40%;
}
</style>
</head>
<body>
<div id="form">
<form method = "post" action = "test.htm" >
UserName: <input type="text" name = "username" />
</form>
</div>
</body>
</html>上面代码的输出结果是:

发布于 2014-01-31 18:02:42
您可以使用下面的css代码使文本框在水平和垂直方向居中。
#form {
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 100px;
height: 100px;
}发布于 2014-01-31 17:46:08
这就是你要的。
CSS更改:
div#form form {
background: none repeat scroll 0 0 #808080;
display: block;
height: 100px;
line-height: 100px;
margin: 0 auto;
text-align: center;
vertical-align: middle;
width: 100%;
}希望这能有所帮助。
https://stackoverflow.com/questions/21476827
复制相似问题