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.

how to specify font sizes<br />

Adjusting font sizes<br />

Now that Tony has a new set of fonts, we need to work on those font sizes, as most<br />

people find the default sizes of the headings a bit large, at least aesthetically. To do<br />

that, you need to know how to specify font sizes, and there are actually a few ways to<br />

do this. Let’s take a look at some ways to specify font-size and then we’ll talk<br />

about how best to specify font size so they are consistent and user friendly.<br />

px<br />

352 Chapter 9<br />

You can specify your font size in pixels, just like the pixel dimensions you used<br />

for images in Chapter 5. When you specify font size in pixels, you’re telling<br />

the browser how many pixels tall the letters should be.<br />

font-size: 14px;<br />

The px must come right after the number of<br />

pixels. You can’t have a space in between.<br />

Here’s how you’d specify<br />

font-size <strong>with</strong>in a body rule.<br />

body {<br />

font-size: 14px;<br />

}<br />

%<br />

font-size: 150%;<br />

In <strong>CSS</strong> you specify pixels <strong>with</strong><br />

a number followed by “px”.<br />

This says that the font-size<br />

should be 14 pixels high.<br />

h i p<br />

14 pixels<br />

Setting a font to 14 pixels high<br />

means that there will be 14<br />

pixels between the lowest part of<br />

the letters and the highest.<br />

Unlike pixels, which tell the font exactly how big it should be in pixels, a font size specified<br />

as a percentage tells the font how big it should be relative to another font size. So,<br />

says that the font size should be<br />

150% of another font size. But,<br />

which other font size? Well, since<br />

font-size is a property that is<br />

inherited from the parent element,<br />

when you specify a % font size, it is<br />

relative to the parent element. Let’s<br />

check out how that works...<br />

If you do things right, any<br />

user will be able to increase<br />

the font sizes on your Web<br />

page for readability. You’ll<br />

see how in a couple of pages.<br />

Here we’ve specified a body font size in<br />

pixels, and a level one heading as 150%.<br />

body {<br />

font-size: 14px;<br />

}<br />

h1 {<br />

font-size: 150%;<br />

}

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

Saved successfully!

Ooh no, something went wrong!