Want to improve this question? Update the 开发者_StackOverflow中文版question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this questionI want to request info from user. See example below:
Your Name: |_________|
Age: |_________|
Address: |_________|
What is the best way to code the above in HTML?
- It is best to implement it in div. Have left and right div for
label
andinput
- It is best to implement it in table
- No
- No
You only need the labels and inputs.
label {
width: 16em; /* Adjust for taste */
padding-right: 1em;
text-align: right;
float: left;
clear: left;
}
Form styling via CSS is clean and practical, and has the added benefit of using HTML markup in the way it was intended.
Your form HTML can be written like this:
<form>
<label>Your Name:</label>
<input type="text" name="your_name" /><br />
<label>Age:</label>
<input type="text" name="age" /><br />
<label>Address:</label>
<input type="text" name="address" /><br />
</form>
Your CSS will look like this:
<style type="text/css">
form label {
float: left;
width: 100px;
text-align: right;
}
form input {
float: left;
width: 335px;
text-align: left;
}
form br {
clear: both;
}
</style>
Tables are designed for tabular data. If you would expect to see your data in a spreadsheet, you can use it in an HTML table. Otherwise, CSS should be used to style your layout.
Any more I do forms in a table
since I hate fighting with the differences in browsers with how they position controls with css.
精彩评论