Layout and Presentation
ON THIS PAGE
HTML tables can be used very effectively to layout your form components. You can also use two special form elements,
fieldset and legend, which will help spiff up your form's appearance and structure. These elements are described below.- Fieldset ~ The fieldset element can be used to draw a box around a group of form components. This element requires both start and end tags. It has no special attributes to speak of however it should be used in conjunction with the
legendelement otherwise it's rather pointless. Each set of<fieldset>...</fieldset>tags contains all the form components you wish to be grouped together. - Legend ~ The
legendelement creates a text label for each fieldset. It must be used inside thefieldsetelement and should be the first element appearing after the<fieldset>start tag. The legend element requires both start and end tags. Each set of<legend>...</legend>tags contains the text you wish to use to label the respectivefieldset.
An Example Form (Advanced)
Below is an example of an advanced feedback form using all the form components described on the previous pages. Below that you will find:
- The HTML source code (which you can copy and modify)
- A quick rundown of the structure
- The structure at a glance
A Quick Rundown of the Structure
- The entire form in the example above is placed inside in a set of
<div>...</div>tags. Thestyleattribute is used in this 'wrapper'divelement to apply some CSS properties which do the following:
- Set the width at 500 pixels (
width: 500px;) - Apply a border 2 pixels in width on all sides
- Color the border light on the top and left sides and dark on the bottom and right sides to render a 3D effect ( e.g.
border-top: 2px solid white;)
- Set the width at 500 pixels (
- The
formelement also has thestyleattribute inserted to apply some CSS properties which do the following:
- Strip the default white space that appears around the
formelement (margin: 0px) - Move the form components (textfields, checkboxes, etc.) away from the border of the
formelement (padding: 10px) - Set the background of the form to a light gray
(background: #d9d9d9;)
- Strip the default white space that appears around the
- The form is divided into three distinct sections. Each section is wrapped in a set of
<fieldset>...</fieldset>tags which draws a nice border around each group of components. Thelegendelement is inserted at the start of eachfieldsetto give it a label.
- Inside each fieldset is an HTML table. The table's width is set at 100% to spread the fieldset out to fill the wrapping div element. Each table cell contains an individual form component.
Structure At A Glance
Here's the source code of the example form stripped down and color-coded so that you can visualize the structure at a glance. (Note: Table rows and cells are implied.)
<div style="CSS properties...">
<form action="" method="post" style="CSS properties...">
<fieldset>
<legend>Fieldset label</legend>
<table>Form components...</table>
</fieldset>
<br>
<fieldset>
<legend>Fieldset label</legend>
<table>Form components...</table>
</fieldset>
<br>
<fieldset>
<legend>Fieldset label</legend>
<table>Form components...</table>
</fieldset>
<br>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
</div>
<br>
And thus concludes the Iron Spider series of tutorials on Interactive Forms. If you want to see a fully functioning web form in action, visit my contact page and send me an email.
| <~ BACK | TOP | INTRO |
