22.04.2013 Views

HTML, XHTML & CSS

HTML, XHTML & CSS

HTML, XHTML & 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.

When assigning values to the font-family<br />

property, you can use a list of comma-separated<br />

font names. These names must match<br />

fonts available to a user’s Web browser. If a<br />

font name includes spaces — such as Times<br />

New Roman — enclose it in quotation marks.<br />

h1 {font-family: Verdana, “Times New<br />

Roman”, serif;}<br />

Chapter 9: Introducing Cascading Style Sheets<br />

However, such a large collection of style rules can be hard to manage. <strong>CSS</strong><br />

allows you to combine several declarations in a single style rule that affects<br />

multiple display characteristics for a single selector, like this:<br />

h1 {color: teal;<br />

font-family: Arial;<br />

font-size: 36px;}<br />

All the declarations for the h1 selector are within the same set of brackets<br />

({}) and are separated by semicolons (;). You can put as many declarations<br />

as you want in a style rule; just end each declaration with a semicolon.<br />

The semicolon at the end of the last declaration is optional. Some people<br />

include it to be consistent and end every declaration with a semicolon, but<br />

it’s not necessary. We use it both ways throughout this book, but when you<br />

stop to think about it, it’s a good idea to be consistent and always use a semicolon<br />

for each and every declaration.<br />

From a purely technical standpoint, white space is irrelevant in style sheets<br />

(just as it is in <strong>HTML</strong>), but you should use a consistent spacing scheme to<br />

make it easy to read and edit your style sheets. One exception to this white<br />

space rule occurs when you declare multiple font names in the font-family<br />

declaration. See the “Font family” sidebar for more information.<br />

You can make the same set of declarations apply to a collection of selectors,<br />

too: You just separate the selectors with commas. The following style rule<br />

applies the declarations for text color, font family, and font size to the h1, h2,<br />

and h3 selectors:<br />

h1, h2, h3 {color: teal;<br />

font-family: Arial;<br />

font-size: 300%;}<br />

Font family<br />

In the preceding rule, the browser knows to use<br />

Verdana first; if that’s not available, it looks for<br />

Times New Roman, and then uses a generic<br />

serif font as its last option. Chapter 11 covers<br />

fonts in <strong>CSS</strong>.<br />

137

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

Saved successfully!

Ooh no, something went wrong!