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.

when you don’t want to inherit<br />

Overriding inheritance<br />

By moving the font-family property up into the body, you’ve set that<br />

font style for the entire page. But what if you don’t want the sans-serif<br />

font on every element? For instance, you could decide that you want<br />

elements to use the serif font instead.<br />

Well, then you can override the inheritance by supplying a<br />

specific rule just for . Here’s how you add a rule for <br />

to override the font-family specified in the body:<br />

314 Chapter 8<br />

body {<br />

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

}<br />

h1, h2 {<br />

color: gray;<br />

}<br />

h1 {<br />

}<br />

p {<br />

}<br />

em {<br />

}<br />

html<br />

body<br />

h1 p p<br />

h2<br />

p<br />

img a<br />

em<br />

a<br />

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

color: maroon;<br />

font-family: serif;<br />

The font-family property is set in<br />

the body rule, so every element inside<br />

the body inherits the sans-serif<br />

font-family property from .<br />

But you’ve decided you want your <br />

elements to have the serif font-family<br />

instead. You need to override the<br />

inheritance <strong>with</strong> a <strong>CSS</strong> rule.<br />

To override the font-family property<br />

inherited from body, add a new rule<br />

selecting em <strong>with</strong> the font-family<br />

property value set to serif.

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

Saved successfully!

Ooh no, something went wrong!