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.

Using <strong>CSS</strong> <strong>with</strong> X<strong>HTML</strong><br />

We’re sure <strong>CSS</strong> has a bright future in the home design category, but let’s get<br />

back to X<strong>HTML</strong>. X<strong>HTML</strong> doesn’t have rooms, but it does have elements<br />

and those elements are going to be the locations that we’re styling. Want to<br />

paint the walls of your elements red? No problem; only paragraphs<br />

don’t have walls, so you’re going to have to settle for the paragraph’s<br />

background-color property instead. Here’s how you do that:<br />

The first thing you do is select the<br />

element you want to style, in this case<br />

the element. Notice in <strong>CSS</strong>, you<br />

don’t put around the name.<br />

p {<br />

}<br />

Place all the styles<br />

for the element in<br />

between { } braces.<br />

You could also write the rule like this:<br />

Then you specify the property you<br />

want to style, in this case the <br />

element’s background color.<br />

background-color: red;<br />

There’s a colon in between the<br />

property and its value.<br />

p { background-color: red; }<br />

Here, all we’ve done is remove the linebreaks. Like X<strong>HTML</strong>, you can format<br />

your <strong>CSS</strong> pretty much as you like. For longer rules you’ll usually want to add<br />

some linebreaks and indenting to make the <strong>CSS</strong> more readable (for you).<br />

Wanna add more style?<br />

And you’re going to set the<br />

background-color to red.<br />

At the end,<br />

put a semicolon.<br />

You can add as many properties and values as you like in each <strong>CSS</strong> rule. Say you<br />

wanted to put a border around your paragraphs, too. Here’s how you do that:<br />

p {<br />

}<br />

background-color: red;<br />

border: 1px solid gray;<br />

We call the whole<br />

thing a RULE.<br />

All you have to do is add<br />

another property and value.<br />

The element<br />

will have a border......that is 1 pixel thick, solid, and gray.<br />

getting started <strong>with</strong> css<br />

you are here 289

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

Saved successfully!

Ooh no, something went wrong!