CSS Examples Tableless forms using CSS
Author: CSS Drive
This CSS example transforms a conventional form so it's tableless. A form that doesn't use tables for its layout is much more lightweight and semantically correct.
The CSS:
<style type="text/css">
label{
float: left;
width: 120px;
font-weight: bold;
}
input, textarea{
width: 180px;
margin-bottom: 5px;
}
textarea{
width: 250px;
height: 150px;
}
.boxes{
width: 1em;
}
#submitbutton{
margin-left: 120px;
margin-top: 5px;
width: 90px;
}
br{
clear: left;
}
</style>
The HTML:
<form>
<label for="user">Name</label>
<input type="text" name="user" value="" /><br />
<label for="emailaddress">Email Address:</label>
<input type="text" name="emailaddress" value="" /><br />
<label for="comments">Comments:</label>
<textarea name="comments"></textarea><br />
<label for="terms">Agree to Terms?</label>
<input type="checkbox" name="terms" class="boxes" /><br />
<input type="submit" name="submitbutton" id="submitbutton" value="Submit" />
</form>
By floating the "label" tag to the left, the text description of each form field appears to the left, resulting in a "two column" look for the form. The width of the "label" is controlled, so it will comfortably contain the longest text description in the form. I throw in a <br> tag with "clear: left" after each form field to prevent the floating <label> tag from potentially spilling over to content beneath it. Margins such as "margin-top" and "margin-bottom" are also used to add some nice margins between form fields.
Comments (108)
Cool and Clear. Fine. Thanks.
Ruby
It will not work on multicolumn based form layout.
gg amk dsaiuja akfdja
What is the client side data gathering piece?
it is a vv nice scc form
visit http://hanif.net.tc
e mail .(JavaScript must be enabled to view this email address)
Hey this example is beautiful
nice website.. cheers !!!
Hello
Nice website
Cheers
"Tables are certianly not the ideal solution."
Could you please explain why?!
That's exactly why tables are existing in HTML: to represent tabular data, like the form in this example.
I think you've misunderstood something very badly here. You should not use table element for layout design (header, footer, sidebars, menu, etc), but always use it for tabular data. It's sematically incorrect to represent tabular data without using tables.