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 keywords for size<br />

354 Chapter 9<br />

keywords<br />

There’s one more way to specify font sizes: keywords. You<br />

can specify a font size as xx-small, x-small, small,<br />

medium, large, x-large, or xx-large and the<br />

browser will translate these keywords into pixel values using<br />

defaults that are defined in the browser.<br />

This is typically how the various keyword sizes relate to<br />

one another. Each size is about 20% larger than the<br />

previous size and small is usually defined to be around<br />

12 pixels in height. Keep in mind, however, that the<br />

keywords aren’t always defined the same way in every<br />

browser, and that users can redefine them if they want.<br />

body {<br />

font-size: small;<br />

}<br />

So, how should I specify my font sizes?<br />

You’ve got quite a few choices for specifying font sizes: px, em, percentages,<br />

and keywords. So, which do you use? Here’s a recipe for specifying font sizes<br />

that will give you consistent results for most browsers.<br />

1<br />

2<br />

In most browsers this will result in the<br />

body text being about 12 pixels.<br />

Choose a keyword (we recommend small or medium) and specify it as the<br />

font size in your body rule. This acts as the default size for your page.<br />

Specify the font sizes of your other elements relative to your body font size<br />

using either em or percentages (the choice between em and percentages<br />

is yours, as they are essentially two ways to do the same thing).<br />

Nice recipe, but what’s good about it? By defining your fonts relative to the<br />

body font size, it’s really easy to change the font sizes in your Web page simply<br />

by changing the body font size. Want to redesign the page to make the fonts<br />

larger? If your body font size value is small, simply change it to medium<br />

and, voilà – every other element will automatically get larger in proportion<br />

because you specified their font sizes relative to the body’s font size. Better yet,<br />

say your users want to resize the fonts on the page. Again, no problem; using<br />

this recipe, all the fonts on the page will automatically readjust.<br />

xx-small<br />

x-small<br />

small<br />

medium<br />

large<br />

x-large<br />

xx-large

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

Saved successfully!

Ooh no, something went wrong!