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.

class selectors<br />

Creating a selector for the class<br />

To select a class, you write the selector like this:<br />

The p selector<br />

is first.<br />

318 Chapter 8<br />

body {<br />

font-family: sans-serif;<br />

}<br />

h1, h2 {<br />

color: gray;<br />

}<br />

h1 {<br />

}<br />

p {<br />

}<br />

Then use a “.” to<br />

specify a class.<br />

p.greentea {<br />

color: green;<br />

}<br />

This selector selects<br />

all paragraphs in the<br />

greentea class.<br />

border-bottom: 1px solid black;<br />

color: maroon;<br />

p.greentea {<br />

color: green;<br />

}<br />

Last is the<br />

class name.<br />

So now you have a way of selecting elements that belong to a certain class.<br />

All you need to do is add the class attribute to any elements you want to be<br />

green, and this rule will be applied. Give it a try: open your “lounge.css” file and<br />

add the p.greentea class selector to it.<br />

And here’s the rule... make any<br />

text in a paragraph in the<br />

greentea class the color green.

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

Saved successfully!

Ooh no, something went wrong!