【发布时间】:2012-10-22 22:44:30
【问题描述】:
我想将表单中的元素居中而不移动文本或按钮以使其在左侧对齐。
所以它看起来像这样:
底部的方块应该是一个按钮。
我希望它居中,但 <center> 标签移动了文本和按钮,因此它们位于输入框的中心。
这是我的代码:
<form action="login.php" method="post">
<div class="aside">
<div id="center">
Username:<br>
<input type="text" name="username"><br>
Password:<br>
<input type="password" name="passwor"><br>
<input type="submit" class="button" name="submit" value="Login"><br><br>
</div>
</div>
</form>
和css:
#center{
width: 250px;
margin-left: auto;
margin-right: auto;
}
div.aside {
margin-left: 15px;
margin-top: 10px;
width: 250px;
background: #f5f5f5;
border: 1px solid #e9e9e9;
line-height: 150%;
}
div.aside .button{
padding:3px;
width: 50px;
margin-top: 3px;
background-color: #00A1E6;
border: 1px solid #0184BC;
text-decoration:none;
color: #ffffff;
text-align: center;
-webkit-appearance: none;
}
【问题讨论】:
-
“浮动”样式没有这样的值“中心”。有效值为:“left”、“right”、“none”、“inherit”。 Source.
-
我知道,那是我正在试验的随机废话。我会及时删除。