04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

styling the form<br />

Styling the form and the table <strong>with</strong> <strong>CSS</strong><br />

We just need to add a few styling rules to the X<strong>HTML</strong>, and we’ll be done.<br />

Because this form is part of the Starbuzz site, we’re going to reuse the style in the<br />

“starbuzz.css” style sheet, and create a new style sheet, “styledform.css”, to add<br />

new style rules for the Bean Machine form. All of this <strong>CSS</strong> should be familiar to<br />

you now. We’re not using any rules unique to tables or forms; it’s all just the same<br />

stuff you’ve been using in the last few chapters.<br />

You’ll find this <strong>CSS</strong> in the file “styledform.css” in the folder “chapter14/starbuzz”.<br />

body {<br />

background: #efe5d0 url(images/background.gif) top left;<br />

font-family: Verdana, Helvetica, Arial, sans-serif;<br />

margin: 20px;<br />

}<br />

table {<br />

border: thin dotted #7e7e7e;<br />

padding: 10px;<br />

}<br />

th {<br />

text-align: right;<br />

vertical-align: top;<br />

padding-right: 10px;<br />

padding-top: 2px;<br />

}<br />

td {<br />

vertical-align: top;<br />

padding-bottom: 15px;<br />

}<br />

table table {<br />

border: none;<br />

padding: 0px;<br />

}<br />

table table td {<br />

text-align: right;<br />

padding-bottom: 0px;<br />

}<br />

630 Chapter 14<br />

We’re going to rely on the Starbuzz <strong>CSS</strong> for some of our style,<br />

but we’re changing the body font to a sans-serif font, adding the<br />

Starbuzz background image, and adding a margin to the body.<br />

We’re adding a border around the table,<br />

and some padding between the table<br />

content and the border.<br />

These font properties<br />

will be inherited by all<br />

the elements on the page,<br />

including the text in the<br />

table and the form.<br />

The form labels are in the table headings. We want to align<br />

these to the top and right so they align nicely <strong>with</strong> the<br />

form elements in the right column. We’re also adding a bit<br />

of padding to give them a little bit more space.<br />

The content of the data cells is already aligned<br />

to the left by default, which is what we want,<br />

but we have to align them vertically too, to<br />

match the table headings. We’re adding a bit of<br />

padding here too, to add space between the rows.<br />

Ready Bake<br />

<strong>CSS</strong><br />

These two rules override some of the other properties we set<br />

in the rules for table and td above. Why? Because we don’t<br />

want the nested table to have a border, and we want the<br />

spacing to be tighter, so we’re removing the padding. We also<br />

need to align the form labels in the nested data cells to the<br />

right (those aren’t in table headings, like the others are, so<br />

they’re not aligned <strong>with</strong> the th rule above).

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

Saved successfully!

Ooh no, something went wrong!