04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

deciding how to style forms<br />

To Table or Not to Table? That’s the question...<br />

You’re going to find people on both sides of this issue. Should you use<br />

<strong>CSS</strong> to layout your forms? Or tables? The harsh reality is that laying out<br />

forms <strong>with</strong> <strong>CSS</strong> is difficult. And, if you’d like to bend space and time to lay<br />

out your forms <strong>with</strong> <strong>CSS</strong>, we’ll gladly get out of your way and look on in<br />

admiration. However, many forms are tabular in their layout, so why not use<br />

tables to do the layout of your forms and let <strong>CSS</strong> do the styling? That way,<br />

we get the best of both worlds.<br />

Let’s start <strong>with</strong> the layout...<br />

We’ll start by getting the form into a table. Check out the sketch below<br />

and you’ll see the form fits pretty nicely in a table, and even better, it looks<br />

like a form rather than a ragged collection of input elements. Also notice<br />

that we’ve used a nested table in the “Ship to:” section.<br />

The labels for<br />

each form<br />

element go<br />

in the left<br />

column.<br />

The cell on<br />

the left of<br />

the submit<br />

button is<br />

empty. There’s<br />

no label to<br />

put here.<br />

626 Chapter 14<br />

Here’s the sketch of the table.<br />

It’s a simple table, <strong>with</strong> two<br />

columns and six rows - one row<br />

for each main section of the form.<br />

We’ve thrown all the input<br />

elements into the right-hand<br />

column.<br />

Notice that we’ve grouped each<br />

set of checkboxes and radio<br />

buttons into one table data cell.<br />

The Ship to: section has five text<br />

elements, so we’ve grouped<br />

them into a nested table. The<br />

nested table has the same basic<br />

layout as the main table: two<br />

columns and five rows, <strong>with</strong> one<br />

row for each label / element pair.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!