I am new to html/css. i am trying to build up my own form and i am trying to align it in the center. I used the align property in css but its not working.
Html code:
<!DOCTYPE HTML>
<head>
<title>Web Page Having A Form</title>
<link rel = "stylesheet" type="text/css" href="Form.css">
</head>
<body>
<h1>Create a New Account</h1>
<form >
<table>
<tr>
<td>Name :</td> <td><input type="text" name="name"></td><br>
</tr>
<tr>
<td>Email :</td> <td><input type="text" name="email"></td><br>
</tr>
<tr>
<td>Password :</td> <td><input type="password" name="pwd"></td><br>
</tr>
<tr>
<td>Confirm Password :</td> <td><input type="password" name="cpwd"><br>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
Css Code:
body
{
background-color : #484848;
}
h1
{
color : #000000;
text-align : center;
font-family: "SIMPSON";
}
form
{
align:"center";
}
How should i change my code to align the entire form in the center?
Wrap the <form>
element inside a div
container and apply css to the div
instead which makes things easier.
#aDiv{width: 300px; height: 300px; margin: 0 auto;}
_x000D_
<html>_x000D_
_x000D_
<head></head>_x000D_
_x000D_
<body>_x000D_
<div>_x000D_
<form>_x000D_
<div id="aDiv">_x000D_
<table>_x000D_
<tr>_x000D_
<td>Name :</td>_x000D_
<td>_x000D_
<input type="text" name="name">_x000D_
</td>_x000D_
<br>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Email :</td>_x000D_
<td>_x000D_
<input type="text" name="email">_x000D_
</td>_x000D_
<br>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Password :</td>_x000D_
<td>_x000D_
<input type="password" name="pwd">_x000D_
</td>_x000D_
<br>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Confirm Password :</td>_x000D_
<td>_x000D_
<input type="password" name="cpwd">_x000D_
<br>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>_x000D_
<input type="submit" value="Submit">_x000D_
</td>_x000D_
</tr>_x000D_
</table>_x000D_
</div>_x000D_
</form>_x000D_
</div>_x000D_
</body>_x000D_
_x000D_
</html>
_x000D_
Or you can just use the <center></center>
tags.
I would just use table and not the form. Its done by using margin.
table {
margin: 0 auto;
}
also try using something like
table td {
padding-bottom: 5px;
}
instead of <br />
and also your input should end with />
e.g:
<input type="password" name="cpwd" />
This is my answer. I'm not a Pro. I hope this answer may help you :3
<div align="center">
<form>
.
.
Your elements
.
.
</form>
</div>
Source: Stackoverflow.com