04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

em<br />

body {<br />

font-size: 14px;<br />

}<br />

h1 {<br />

font-size: 150%;<br />

}<br />

h2 {<br />

font-size: 1.2em;<br />

}<br />

You can also specify font sizes using “em”, which, like percentage, is another<br />

relative unit of measure. With em you don’t specify a percentage; instead you<br />

specify a scaling factor. Here’s how you use em:<br />

font-size: 1.2em;<br />

body is 14px<br />

h1 is 21px p is 14px<br />

The heading is<br />

150% of the <br />

font size, which is 21px.<br />

This says that the<br />

font size should be<br />

scaled by 1.2.<br />

Say you use this measurement to specify the size of an<br />

heading. Your headings will be 1.2 times<br />

the font size of the parent element, which in this case is<br />

1.2 times 14px, which is about 17px.<br />

If we draw a little document tree, you can see that <br />

inherits from , so its font is going to be 150% of<br />

the body’s font size.<br />

Here’s the specified<br />

by a percentage.<br />

Since we didn’t specify a font<br />

size for , it inherits the<br />

font size of 14px.<br />

body is 14px<br />

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

It’s actually 16.8, but<br />

most browsers will<br />

round it up to 17.<br />

Don’t mix this<br />

up <strong>with</strong> the<br />

element!<br />

And here’s the <br />

specified by 1.2em.<br />

h1 is 21px p is 14px h2 is 17px<br />

you are here 353

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

Saved successfully!

Ooh no, something went wrong!