Book HomeCascading Style Sheets: The Definitive GuideSearch this book Friday 28th of November 2014 10:20:28 PM

10.8. Media Types and @-rules

Don't get too excited yet. We aren't talking about media types in the sense of things like audio and video authoring. Well, not exactly, anyway. We're talking about creating rules for presentation within various kinds of media. The defined types of media thus far are:

These are all values of @media, one of several new @-rules. Some others are:

10.8.1. Paged Media

Since I just brought up paged media, I should probably mention that there are some new properties that apply to such media. Five of them apply to page breaks and where they appear:

page-break-before
page-break-after
page-break-inside
orphans
widows 

The first two are used to control whether a page break should appear before or after a given element, and the latter two are common desktop publishing terms for the minimum number of lines that can appear at the end or beginning of a page. They mean the same thing in CSS2 as they do in desktop publishing.

page-break-inside (first proposed by this author, as it happens) is used to define whether or not page breaks should be placed inside a given element. For example, you might not want unordered lists to have page breaks inside them. You would then declare UL {page-break-inside: avoid;}. The rendering agent (your printer, for example) would avoid breaking unordered lists whenever possible.

There is also size, which is simply used to define whether a page should be printed in landscape or portrait mode and the length of each axis. If you plan to print your page to a professional printing system, you might want to use marks, which can apply either cross or crop marks to your page. Thus you might declare:

@page {size: 8.5in 11in; margin: 0.5in; marks: cross;}

This will set the pages to be U.S. letter-standard, 8.5 inches wide by 11 inches tall, and place cross marks in the corners of each page.

In addition, there are the new pseudo-classes :left , :right, and :first, all of which are applied only to the @page rule. Thus, you could set different margins for left and right pages in double-sided printing:

@page:left {margin-left: 0.75in; margin-right: 1in;}
@page:right{margin-left: 1in; margin-right: 0.75in;} 

The :first selector applies only to the first page of a document, so that you could give it a larger top margin or a bigger font size:

@page:first {margin-top: 2in; font-size: 150%;}

10.8.2. The Spoken Word

To round things out, we'll cover some of the properties in the area of aural style sheets. These are properties that help define how a speaking browser will actually speak the page. This may not be important to many people, but for the visually impaired, these properties are a necessity.

First off, there is voice-family, which is much the same as font-family in its structure: the author can define both a specific voice and a generic voice family. There are several properties controlling the speed at which the page is read (speech-rate), as well as properties for the pitch , pitch-range, stress, richness, and volume of a given voice. There are also properties that let you control how acronyms, punctuation, dates, numerals, and time are spoken. There are ways to specify audio cues, which can be played before, during, or after a given element (such as a hyperlink), ways to insert pauses before or after elements, and even the ability to control the apparent position in space from which a sound comes via the properties azimuth and elevation. With these last two properties, you could define a style sheet where the text is read by a voice

The result, shown in Figure 7-33, is a paragraph with a solid top border, a dashed right border, a dotted bottom border, and a solid left border.

Figure 7-33

Figure 7-33. Multiple border styles on a single element

Again we see the top-right-bottom-left order of values. This is just like the ability to set different margins with multiple values. All the same rules about value "in front of" the user, whereas background music comes from "behind" and audio cues come from "above" the user!



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.

A perfect example is an unordered list, in which the list itemsfollow one another. Assume that the following is declared for a listthat contains five list items:

LI {margin-top: 10px; margin-bottom: 15px;}

Thus, each list item has a 10-pixel top margin and a 15-pixel bottommargin. However, when the list is rendered, the distance betweenadjacent list items is 15 pixels, not 25. This is because along thevertical axis, adjacent margins are said to be collapsed. In other

8.4.2.1. Generating a line box

Here arethe steps a user agent has to go through in order to generate a linebox. First, for each inline nonreplaced element (or string of textoutside of an inline element), the font-size isused to determine the initial content-height.Thus, if an inline element has a font-size ofstill perfectly valid. Note that the previous rule would not match the value figure or config, as neither of them starts with fig- or is simply fig. The rule would match fig-tree, however.

10.2.3. More Pseudo-Classes and Pseudo-Elements

Second, all of the inline elements in a given line are alignedaccording to their values for vertical-align. Bydefault, this will cause all text in the line to be aligned alongtheir baselines, but of course differentvertical-align values will have different effects.All of the elements could be top-aligned, for example. We'llreturn to vertical alignment later in the chapter, but for now willassume that everything is baseline-aligned.

Now the line-height comes into play. Let's

You'll remember that I said the second-simplest rule of horizontal formatting was this: the total of the seven horizontal properties always equals the width of the parent element. At first glance, this can be interpreted to mean that an element can never be wider than its parent's content area -- and as long as all properties are zero or greater, that's quite true. However, consider the following, depicted in Figure 8-19:

DIV {width: 400px; border: 3px solid black}