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.

Let’s look at how this all works. <strong>First</strong>, you set a size for your<br />

element. Then, you set all the other font sizes relative to<br />

that size, like this:<br />

body { font-size: small; }<br />

h1 { font-size: 150%; }<br />

h2 { font-size: 120%; }<br />

That gives you a document tree that looks like this:<br />

The font size of <br />

is 150% the font size<br />

of .<br />

body is small<br />

h1 is 150% of body p is small h2 is 120% of body<br />

The doesn’t have a font-size value set, so<br />

by default, it inherits the font size.<br />

Now, let’s say you decide to make your<br />

font size bigger, OR the user makes the<br />

font size bigger using the browser.<br />

All your other elements<br />

automatically get bigger too,<br />

<strong>with</strong>out you having to do a thing.<br />

body is large<br />

We’ve set ’s<br />

font size to 120%<br />

of its parent’s size.<br />

Now, let’s say you want to increase the size of the fonts on the page,<br />

or perhaps the user does. Then you get a tree that looks like this:<br />

h2 is still 120% the size of<br />

the body font size. In this<br />

case it’s 120% of “large”.<br />

h1 is 150% of body p is large h2 is 120% of body<br />

Now the body font size has changed to large, and everything else has<br />

changed too, in relation to the body font size. That’s great, because<br />

you didn’t have to go through and change all your other font sizes;<br />

all you had to do was change the body font size. And if you’re a user,<br />

everything happened behind the scenes. When you increased the text<br />

size, all the text got bigger because all the elements are sized relative to<br />

one another, so the page still looks good at a larger font size.<br />

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

Internet Explorer<br />

does NOT<br />

support text<br />

scaling when the font size<br />

is specified using pixels.<br />

Watch it!<br />

Unfortunately, Internet Explorer<br />

users cannot resize fonts if your<br />

font sizes are specified using<br />

pixels. So, that’s one reason to<br />

stay away from pixel sizes. If you<br />

use pixels, you’ll be reducing the<br />

accessibility of your pages for<br />

many of your users.<br />

Fortunately, if you follow the<br />

recipe of supplying a keyword to<br />

define your body’s font size, and<br />

use relative sizes for your other<br />

elements using em or %, then IE<br />

will properly scale your fonts if the<br />

browser is asked to make the text<br />

bigger or smaller.<br />

you are here 355

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

Saved successfully!

Ooh no, something went wrong!