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.

Specifying font families using <strong>CSS</strong><br />

Okay, so there are a lot of good fonts out there from several font families. How do<br />

you get them in your pages? Well, you’ve already had a peek at the font-family<br />

property in the last chapter, when you specified a font-family of “sans-serif ” for<br />

the lounge. Here’s a more interesting example:<br />

body {<br />

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

}<br />

You can specify more than one<br />

font using the font-family<br />

property. Just type the font<br />

names separated by commas.<br />

Check to see if the font<br />

Verdana is available on the<br />

computer and if so, use<br />

it as the font for this<br />

element (in this case, the<br />

element).<br />

Write font names as they<br />

are spelled, including upper-<br />

and lower-case letters.<br />

How font-family specifications work<br />

Here’s how the browser interprets the fonts listed in your font-family specification:<br />

styling <strong>with</strong> fonts and colors<br />

Always put a generic font family name at the<br />

end, like “serif”, “sans-serif”, “cursive”, or<br />

“monospace”. You’ll see what this does in a sec.<br />

body {<br />

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

}<br />

If Verdana isn’t<br />

available, then look<br />

for the font Geneva,<br />

and if it is available,<br />

use it for the body.<br />

The font-family property gives you a way to create a list of preferred fonts.<br />

Hopefully most browsers will have one of your first choices, but if not, you can at least<br />

be assured that the browser will provide a generic font from the same family.<br />

Let’s get some fonts into your pages...<br />

Usually your font-family specification contains a<br />

list of alternative fonts, all from the same family.<br />

If Geneva isn’t<br />

available, then look for<br />

the font Arial, and if<br />

it is available, use it<br />

for the body.<br />

Finally, if none of the specific<br />

fonts can be found, just use<br />

whatever the browser considers<br />

its default “sans-serif” font.<br />

You don’t have to specify four alternative fonts; you<br />

can have two, three, etc. In the last chapter we only<br />

used one - the default sans-serif font - although<br />

we don’t recommend that because it doesn’t give you<br />

much control over the fonts you’d like used.<br />

you are here 347

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

Saved successfully!

Ooh no, something went wrong!