Section 5.4. Styles and Variants


5.4. Styles and Variants

Compared with everything we've covered so far, this section is practically a no-brainer. The properties discussed herein are so straightforward, and the complexities are so minimal, that this discussion will probably come as a great relief. First, we'll talk about font-style, and then move on to font-variant before wrapping up with the font properties.

5.4.1. Fonts with Style

font-style is very simple: it's used to select between normal text, italic text, and oblique text. That's it! The only complication is in recognizing the difference between italic and oblique text and in understanding why browsers don't always give you a choice.

font-style


Values:

italic | oblique | normal | inherit


Initial value:

normal


Applies to:

All elements


Inherited:

Yes


Computed value:

As specified


The default value of font-style is, as you can see, normal. This refers to "upright" text, which is probably best described as "text that is not italic or otherwise slanted." The vast majority of text in this book is upright, for instance. That leaves only an explanation of the difference between italic and oblique text. For that, it's easiest to refer to Figure 5-16, which illustrates the differences very clearly.

Figure 5-16. Italic and oblique text in detail


Basically, italic text is a separate font face, with small changes made to the structure of each letter to account for the altered appearance. This is especially true of serif fonts, where, in addition to the fact that the text characters "lean," the serifs may be altered in an italic face. Oblique text, on the other hand, is simply a slanted version of the normal, upright text. Font faces with labels like "Italic," "Cursive," and "Kursiv" are usually mapped to the italic keyword, while oblique is often assigned faces with labels such as "Oblique," "Slanted," and "Incline."

If you want to make sure that a document uses italic text in familiar ways, you could write a style sheet like this:

 p {font-style: normal;} em, i {font-style: italic;} 

These styles would make paragraphs use an upright font, as usual, and cause the em and i elements to use an italic fontagain, as usual. On the other hand, you might decide that there should be a subtle difference between em and i:

 p {font-style: normal;} em {font-style: oblique;} i {font-style: italic;} 

If you look closely at Figure 5-17, you'll see there is no apparent difference between the em and i elements. In practice, not every font is so sophisticated as to have both an italic face and an oblique face, and even fewer web browsers are sophisticated enough to tell the difference when both faces do exist.

Figure 5-17. More font styles


If either of these is the case, then there are a few things that can happen. If there is no "Italic" face, but there is an "Oblique" face, then the latter can be used for the former. If the situation is reversedan "Italic" face exists, but there is no defined "Oblique" facethe user agent may not substitute the former for the latter, according to the specification. Finally, the user agent can simply generate the oblique face by computing a slanted version of the upright font. In fact, this is what most often happens in a digital world, where it's fairly simple to slant a font using a simple computation.

Furthermore, you may find that in some operating systems, a given font that has been declared as italic may switch from being italic to oblique depending on the actual size of the font. The display of Times on a Macintosh running the Classic OS (Mac OS 9), for example, is shown in Figure 5-18, and the only difference is a single pixel in size.

Figure 5-18. Same font, same style, different sizes


There isn't much that can be done about this, unfortunately, except better font handling by operating systems, such as that found in Mac OS X and Windows XP. Usually, the italic and oblique fonts look exactly the same in web browsers.

Still, font-style can be useful. For example, it is a common typographic convention that a block quote should be italicized, but that any specially emphasized text within the quote should be upright. To employ this effect, which is illustrated in Figure 5-19, you would use these styles:

 blockquote {font-style: italic;} blockquote em, blockquote i {font-style: normal;} 

Figure 5-19. Common typographical conventions through CSS


5.4.2. Font Variations

In addition to sizes and styles, fonts can also have variants. CSS offers a way to address one very common variant.

font-variant


Values:

small-caps | normal | inherit


Initial value:

normal


Applies to:

All elements


Inherited:

Yes


Computed value:

As specified


As for font-variant, it has only two non-inherit values: the default of normal, which describes ordinary text, and small-caps, which calls for the use of small-caps text. If you aren't familiar with such an effect, IT LOOKS SOMETHING LIKE THIS. Instead of upper- and lowercase letters, a small-caps font employs uppercase letters of different sizes. Thus, you might see something like that shown in Figure 5-20:

 h1 {font-variant: small-caps;} h1 code, p {font-variant: normal;} <h1>The Uses of <code>font-variant</code> On the Web</h1> <p> The property <code>font-variant</code> is very interesting... </p> 

Figure 5-20. The small-caps value in use


As you may notice, in the display of the H1 element, there is a larger uppercase letter wherever an uppercase letter appears in the source and a small uppercase letter wherever there is a lowercase letter in the source. This is very similar to text-TRansform: uppercase, with the only real difference being that, here, the uppercase letters are of different sizes. However, the reason that small-caps is declared using a font property is that some fonts have a specific small-caps face, which a font property is used to select.

What happens if no such face exists? There are two options provided in the specification. The first is for the user agent to create a small-caps face by scaling uppercase letters on its own. The second is simply to make all letters uppercase and the same size, exactly as if the declaration text-transform: uppercase; had been used instead. This is obviously not an ideal solution, but it is permitted.

Internet Explorer for Windows took the all-caps route before IE6. Most other browsers display small-caps text when asked to do so.





CSS(c) The Definitive Guide
CSS: The Definitive Guide
ISBN: 0596527330
EAN: 2147483647
Year: 2007
Pages: 130
Authors: Eric A. Meyer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net