.cls_forgotpwd_container
{
font-family: sans-serif;
font-size: 13px;
width: 350px;
/*margin: auto;*/
width: 350px;
display: table-cell;
vertical-align: middle;
}
.cls_forgotpwd_table label
{
margin-right: 10px;
}
.cls_forgotpwd_table input[type="password"]
{
width: 200px;
height: 20px;
border: 1px solid #555;
}
body
{
display: table;
}
<div class="cls_forgotpwd_container">
<form class="cls_forgotpwd_form" id="forgotpwd_form">
<table class="cls_forgotpwd_table">
<tbody>
<tr>
<td><label>Password</label></td>
<td><input type="password" name="password"></input></td>
</tr>
<td><label>Confirm Password</label></td>
<td><input type="password" name="confirm_password"></input></td>
<tr>
<td><input class="cls_submit" type="submit" name="submit" value="Change It"></input></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</form>
</div>
惑
1)我試圖display: table
和tabel-cell with vertical-align:middle
但它不是我的情況下工作。而這些數據不是表格,所以我不認爲它是一個正確的方法。
2)我不喜歡position absolute
與top and left values in %
。如果我沒有其他選擇,我會選擇這個。
是否有任何其他可能中心對齊div?或者我應該在以上兩個選項中使用哪一個?如果我必須選擇option1,則不適用於我的情況。
我不喜歡margin
來居中對齊。 IE不支持flex
。
margin:0 auto
與width:350px
成功對齊div。
有什麼建議嗎?
使用的margin-top:50%保證金左:50% – Alex
也許這樣http://jsfiddle.net/soledar10/dwr7mq70/ – Dmitriy
@Dmitriy你可以添加它作爲答案。 –