XML technologies / CSS / CSS Cookbook / Forms / Design example: registration form

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Some forms benefit from placing elements form in a two-column table: one column for fields, the other for labels. The example shows the code; the next figure shows the unstyled form.

Example: A styled form.

<form action="registration.cfm" method="post">
  <table cellspacing="0">
    <tr class="header">
      <th colspan="2">Informationen zum Benutzerkonto</th>
    </tr>
    <tr class="required">
      <th scope="row">Login-Name*</th>
      <td><input name="uname" type="text" size="12" maxlength="12" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Passwort*</th>
      <td><input name="pword" type="text" size="12" maxlength="12" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Passwort best&auml;tigen* </th>
      <td><input name="pword2" type="text" size="12" maxlength="12" /></td>
    </tr>
    <tr class="required">
      <th scope="row">E-Mail-Adresse*</th>
      <td><input name="email" type="text" /></td>
    </tr>
    <tr class="required">
       <th scope="row">E-Mail-Adresse best&auml;tigen*</th>
       <td><input type="text" name="email2" /></td>
    </tr>
    <tr class="header">
      <th colspan="2">Informationen zur Person</th>
    </tr>
    <tr class="required">
      <th scope="row">Vorname*</th>
      <td><input name="fname" type="text" size="11" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Nachname*</th>
      <td><input name="lname" type="text" size="11" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Adresse 1*</th>
      <td><input name="address1" type="text" size="11" /></td>
    </tr>
    <tr>
      <th scope="row">Adresse 2</th>
      <td><input type="text" name="address2" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Stadt*</th>
      <td><input type="text" name="city" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Bundesland*</th>
      <td>
        <select name="state">
          <option selected="selected" disabled="disabled">Ausw&auml;hlen</option>
          <option value="hamburg">Hamburg</option>
        </select>
      </td>
    </tr>
    <tr class="required">
      <th scope="row">PLZ*</th>
      <td><input name="zipcode" type="text" id="zipcode" size="5" maxlength="5" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Land*</th>
      <td><input type="text" name="country" id="country" /></td>
    </tr>
    <tr class="required">
      <th scope="row">Geschlecht*</th>
      <td><input type="radio" name="sex" value="female" />Weiblich <input type="radio" name="sex" value="male" />M&auml;nnlich</td>
    </tr>
    <tr class="header">
      <th colspan="2">Weitere Informationen</th>
    </tr>
    <tr>
      <th scope="row">Jahreseinkommen</th>
      <td>
        <select name="income" size="1" >
          <option selected="selected" disabled="disabled">Ausw&auml;hlen</option>
          <option value="notsay">Verrate ich nicht!</option>
        </select>
      </td>
    </tr>
    <tr>
      <th scope="row">Interessen</th>
      <td><input name="interests" type="checkbox" value="shopping-fashion" />Einkaufen/Mode <input name="interests" type="checkbox" value="sports" />Sport <input name="interests" type="checkbox" value="travel" />Reisen</td>
    </tr>
    <tr>
      <th scope="row">Augenfarbe</th>
      <td><input name="eye" type="checkbox" value="red" />Rot <input name="eye" type="checkbox" value="green" />Gr&uuml;n <input name="eye" type="checkbox" value="brown" />Braun <input name="eye" type="checkbox" value="blue" />Blau-Golden</td>
    </tr>
  </table>
  <input type="submit" name="Submit" value="Abschicken" id="buttonSubmit" />
  <input type="reset" name="Submit2" value="Formular l&ouml;schen" id="buttonReset" />
</form>

Form and table without styles

Figure: Form and table without styles.

First style the element table itself. The property border-collapse controls borders between cells. Also define table color and borders (see the following figure):

The table now has a border

Figure: The table now has a border.

table {
 border-collapse: collapse;
 color: black;
 border: 1px solid black;
}

Next style label cells, here elements th (see the next figure). They are 200 pixels wide, right-aligned and use Verdana at 0.7em:

th {
 width: 200px;
 text-align: right;
 vertical-align: top;
 border-top: 1px solid black;
 font-family: Verdana;
 font-size: 0.7em;
}

Styled label cells

Figure: Styled label cells.

Add padding to the label cells (see the next figure):

th {
 width: 200px;
 text-align: right;
 vertical-align: top;
 border-top: 1px solid black;
 font-family: Verdana;
 font-size: 0.7em;
 padding-right: 12px;
 padding-top: 0.75em;
 padding-bottom: 0.75em;
}

Label cells with padding

Figure: Label cells with padding.

Next style the right-hand cells. A black background distinguishes them from the left column. Gray left borders soften the reading transition from left to right (see the next figure):

td {
 vertical-align: middle;
 background-color: black;
 border-bottom: 1px solid white;
 color: white;
 border-left: 4px solid gray;
 padding: 4px;
 font-family: Verdana;
 font-size: .7em;
}

Styled right-hand cells

Figure: Styled right-hand cells.

Some fields are mandatory for registration. Indicate this with red text in their cells (see the next figure):

.required {
 color: red;
}

Required fields appear in red

Figure: Required fields appear in red.

Distinguish section headings with uppercase letters and a slightly larger font (see the next figure):

.header th {
 text-align: left;
 text-transform: uppercase;
 font-size: .9em;
}

Adjusted section headings

Figure: Adjusted section headings.

Move headings above the second column. Calculate their position, defined here with left padding, by adding the left column’s width (200 pixels), its right padding (12 pixels), the right column’s left border (4 pixels) and its left padding (4 pixels):

.header th {
 text-align: left;
 text-transform: uppercase;
 font-size: .9em;
 padding-left: 220px;
}

Thicken the top and bottom borders to make headings more attractive (see the next figure):

.header th {
 text-align: left;
 text-transform: uppercase;
 font-size: .9em;
 padding-left: 220px;
 border-bottom: 2px solid gray;
 border-top: 2px solid black;
}

Section headings with padding

Figure: Section headings with padding.

Finally, move submit and reset buttons right, like the headings, placing them under the input fields with a 220-pixel left margin (see the following figure):

#buttonSubmit {
 margin-left: 220px;
 margin-top: 4px;
}

Repositioned submit and reset buttons

Figure: Repositioned submit and reset buttons.

  

 

 

 

back to top