Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

Grouping Controls with fieldset and legend 351

12


Input ▼



Output ▼


As you can see, I’ve changed the background color of the field set and assigned a specific
width. I’ve also aligned the legend to the right. Because of the default browser position-
ing of the legend, the background color splits the legend text. This is an example of how
browsers treat legends uniquely. To set a background for the field set that includes the
full legend, I’d have to wrap the field set in another block-level element (like a div) and
apply the background color to that.


Changing the Default Form Navigation


In most browsers, you can use the Tab key to step through the form fields and links on
a page. When filling out long forms, it’s often much easier to use the Tab key to move
from one field to the next than to use the mouse to change fields. If you have a mix of
form fields and links on your page, setting things up so that using Tab skips past the links
and moves directly from one form field to the next can improve the usability of your
applications greatly. To set the tab order for your page, use the tabindex attribute. You


FIGURE 12.23
The fieldset and
legend elements
enable you to orga-
nize your forms.

Free download pdf