我想有一個文本框在中心。我嘗試了下面的代碼。但它並沒有把它放在中心位置。輸出的圖像也可以在下面找到。請通過在我的代碼中指出錯誤來幫助我。如何在中心使用保證金屬性在中心Div元素
<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>
我從上面的代碼輸出爲:
設置'margin:0 auto;' –
檢查下面的答案。 - @Abhinav – Nitesh