【发布时间】:2011-09-30 15:23:56
【问题描述】:
我在这里查看了许多不同的答案,它们似乎都归结为 text-align: center 在父 div 的样式中。我已经尝试过了,它适用于标签,但不适用于实际的输入元素。
这是基本代码:
html
<div id="content">
<div id="login_form">
<h2>Log in to DOT Voting</h2>
<form>
<label for="username">Username</label>
<input type="text" name="username" value="" />
<label for="password">Password</label>
<input type="password" name="password" value="" />
<input type="submit" name="submit" value="Log In" />
</div>
</div>
css
#login_form {
width:90%;
background-color: #bdd2ff;
border: 1px solid white;
margin: 50px auto 0;
padding: 1em;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
text-align: center;
}
input[type=text], input[type=password] {
text-align:center;
display: block;
margin: 0 0 1em 0;
width: 90%;
border: 1px solid #818181;
padding: 5px;
}
input[type=submit] , form a {
border: none;
margin-right: 1em;
padding: 6px;
text-decoration: none;
font-size: 12px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
background: #cfdeff;
color: black;
box-shadow: 0 1px 0 white;
-moz-box-shadow: 0 1px 0 white;
-webkit-box-shadow: 0 1px 0 white;
}
input[type=submit]:hover, form a:hover {
background: #007cc2;
cursor: pointer;
}
login_form div 以页面为中心,表单标签以 div 为中心,提交按钮以 div 为中心。但是文本输入框没有居中。我能做些什么来迫使他们居中? (我不在乎输入框的内容是否居中;我只希望框本身在 div 中居中。)
【问题讨论】: