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.

But how do I use id in <strong>CSS</strong>?<br />

You select an element <strong>with</strong> an id almost exactly like you select an element <strong>with</strong> a<br />

class. To quickly review: if you have a class called “specials”, there are a couple<br />

of ways you can select elements using this class. You could select just certain<br />

elements in the class, like this:<br />

p.specials {<br />

color: red;<br />

}<br />

.specials {<br />

color: red;<br />

}<br />

This selects only paragraphs that are in the specials class.<br />

Or, you can select all the elements that belong to the “specials” class, like this:<br />

This selects all elements in the specials class.<br />

Using an id selector is very similar. To select an element by its id, you use a “#” character<br />

in front of the id (compare this to class, where you use a “.” in front of the class name).<br />

Say you want to select any element <strong>with</strong> the id “footer”:<br />

#footer {<br />

color: red;<br />

}<br />

This selects any element that has the id “footer”.<br />

Or, you could select only a element <strong>with</strong> the id “footer”, like this:<br />

p#footer {<br />

color: red;<br />

}<br />

This selects a element if it has the id “footer”.<br />

The only other difference between class and id is that an id selector should match<br />

only one element in a page.<br />

the box model<br />

you are here 417

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

Saved successfully!

Ooh no, something went wrong!