In many ways, forms are the real workhorses of the Web, but that doesn’t mean they have to be plain. Until CSS Sizing use became prevalent, little could be done to alter the way forms and form elements looked on the Web. Standardizing text field sizes between PC and Macintosh was a problem because the different operating systems interpreted character width differently; moreover, the field sizes may vary from browser to browser.
CSS form design gives the designer much more flexibility, both to integrate and isolate the form and form elements. Text fields, for example, can take on a shade of a site’s background color or adopt the same typeface used on the page. Similarly, you can draw attention to the form itself by giving it a contrasting background; this enables you to format lengthy drop-down lists for easy reading.
Encompassing the Form
The form tag is a containing element that, like the div tag, is not rendered by default. Both tags, in fact, can be styled with CSS – you can even position a form on the page via CSS declarations. Browser support varies for some of the more esoteric CSS properties applied to the form tag, but more common attributes such as background color and border are rendered properly in most cases. Best of all, if CSS does not support certain attributes, these attributes are just ignored and the form renders plainly.
Frequently, a Web page only contains a single form. In these situations, styling the form tag itself will have the desired results. For example, this CSS rule gives the entire form a bright orange background and a blue border:
border: thin solid #0000FF;
Padding is added to move the form elements in from the edges. Should your page contain more than one form and you want to style each one differently, create a CSS ID selector for each form. In this situation, choose the advanced selector in the New CSS Rule dialog box and enter a unique ID – such as form#topform or form#bottomform – in the Selector field. Also set the ID of the form tag when using this method.
Altering Input Fields
One way in which the form and div tags differ in regard to CSS is in the matter of inheritance. Elements within a form do not inherit the CSS properties of the form, but elements within a div tag do inherit the div’s CSS attributes. You must, therefore, take another route for styling all the text fields in a given form. The best way to affect multiple form elements all at once is to style the input tag. You may recall that the input tag is used to create text fields, radio buttons, checkboxes, and Submit buttons.
For example, this CSS rule gives all the input elements a uniform background color as well as a specific color, font, and size for the text fields:
font: 10px Verdana, Arial, Helvetica, sans-serif;
CSS styles the text fields for initial text as well as text entered by the user.
Tip: Remember that a multiline text field is really a different tag textarea than the single-line text field. You have to create a CSS rule for both input and textarea tags.
One of the best uses for CSS and text fields is setting the width. This method is far more flexible and responsive than using the Char Width field on the Property inspector for each individual text field. It is best to set the width on a CSS class rather than alter it directly in the CSS rule for the input tag. Why? The width setting not only affects all the single-line text fields, but it also alters checkboxes and radio buttons – which are also input tags. After the CSS rule is defined, set the class of a selected text field from the Property Inspector.
Distinguishing Lists and Menus
The select list/menu object is composed of two tags: select and option. The select tag is the overall container for the list items; use the select tag to style the width, typeface, and font size of all drop-down lists on the page uniformly. Individual list items can be styled by setting a class on the separate option tags. Although this operation must be performed by hand and is somewhat tedious, it does open the door to many possibilities.
If you have a very long drop-down list that includes a wide-range of items organized by category, with judicious CSS styling, main category headings can be in one color and subitems in another.
Changing Labels and Legends
A form is more than a collection of text fields and checkboxes; labels play an equally important role in form organization and usability. Form labels are often applied in one of two ways. The standard technique is to place most of the labels in a single column of a table, with the form elements in another. Designers are also increasingly using the label tag as a means of enhancing accessibility. A Dreamweaver CSS methodology is available for whichever route you take when labeling your forms.