Styling Forms with CSS

We have looked at some basic formating with CSS earlier, such as changing the font and using divs, and floating the elements to wrap elements, but now we will look at stylizing the form fields.

One thing which I recently saw, and had an ephaniy about, is instead of using divs to contain the form elements, instead choose to use an unordered list. Since we are dealing with a list of form elements, it even makes since. However, instead of hitting the enter key to go down a line, and getting messed up layout, Dreamweaver will automatically make a new li tag so we can enter new elements in the middle of forms if necessary.

Note: You may need to have multiple unordered lists to make this work correctly for your form. If I have breaks in my form for example, then each section will have its own list.

ul {
margin: 0px;
padding: 0px 0px 0px 1em;
width: 365px;
}
li {
clear: both;
margin: 0px;
padding: 2px 0px;
list-style: none;
}

To that effect, here is a form, fully CSS styled. We will now look at how we styled this form.

Style your Form Elements

input[type="submit"] {
width: 120px;
margin: 0 auto;
float: none;
}

Provide Hints

Hints on what is requested of your visitors is often a good idea. Consider several items to help your user.