Movatterモバイル変換


[0]ホーム

URL:


previous  next  contents  properties  index  


13Paged media

Contents

Note: Several sections of this specification have been updated by other specifications. Please, see"Cascading Style Sheets (CSS) — The Official Definition" in the latestCSS Snapshot for a list of specifications and the sections they replace.

The CSS Working Group is also developingCSS level 2 revision 2 (CSS 2.2).

13.1Introduction to paged media

Paged media (e.g., paper, transparencies, pages that are displayedon computer screens, etc.) differ fromcontinuous media inthat the content of the document is split into one or more discretepages. To handle pages, CSS 2.1 describes how page margins are setonpage boxes, and howpage breaks are declared.

The user agent is responsible for transferring the page boxes of adocument onto the realsheets where the document willultimately be rendered (paper, transparency, screen, etc.). There isoften a 1-to-1 relationship between a page box and a sheet, but thisis not always the case. Transfer possibilities include:

13.2Page boxes: the @page rule

Thepagebox is a rectangular region that contains two areas:

The size of a page box cannot be specified in CSS 2.1.

Authors can specify the margins of a page box inside an@page rule. An @page ruleconsists of the keyword "@page", followed by an optional pageselector, followed by a block containing declarations andat-rules. Comments and white space are allowed, but optional, betweenthe @page token and the page selector and between the page selectorand the block. The declarations in an@page rule are said to be in thepagecontext.

Note: CSS level 2 has no at-rules that may appearinside @page, but such at-rules are expected to be defined inlevel 3.

Thepageselector specifies for which pages the declarationsapply. In CSS 2.1, page selectors may designate the first page,all left pages, or all right pages

The rules for handling malformed declarations, malformedstatements, and invalid at-rules inside @page are as defined insection 4.2, with thefollowing addition: when the UA expects the start of a declaration orat-rule (i.e., an IDENT token or an ATKEYWORD token) but finds anunexpected token instead, that token is considered to be the firsttoken of a malformed declaration. I.e., the rule for malformeddeclarations, rather than malformed statements is used to determinewhich tokens to ignore in that case.

13.2.1Page margins

In CSS 2.1, only themarginproperties ('margin-top','margin-right','margin-bottom','margin-left', and'margin') apply within thepage context. The following diagram shows therelationships between the sheet, page box, and page margins:

Illustration of sheet, pagebox, margin, and page area.   [D]

Example(s):

Here is a simple example which sets all page margins on all pages:

@page {  margin: 3cm;}

Thepage context has no notion offonts, so 'em' and 'ex' units are not allowed. Percentage values onthe margin properties are relative to the dimensions of thepage box; for left and right margins, they referto the width of the page box while for top and bottom margins, theyrefer to the height of the page box. All other units associated withthe respective CSS 2.1 properties are allowed.

Due to negative margin values (either on the page box or onelements) orabsolutepositioning content may end up outside the page box, but thiscontent may be "cut" — by the user agent, the printer, or ultimately,the paper cutter.

13.2.2Page selectors: selecting left, right, and first pages

When printing double-sided documents, thepageboxes on left and right pages may be different. This can beexpressed through two CSS pseudo-classes that may be used in page selectors.

All pages are automatically classified by user agents into eitherthe:left or:rightpseudo-class.Whether the first page of a document is :left or :right depends on themajor writing direction of the root element. For example, the firstpage of a document with a left-to-right major writing direction wouldbe a :right page, and the first page of a document with aright-to-left major writing direction would be a :left page. Toexplicitly force a document to begin printing on a left or right page,authors caninsert a page break beforethe first generated box.

Example(s):

@page :left {  margin-left: 4cm;  margin-right: 3cm;}@page :right {  margin-left: 3cm;  margin-right: 4cm;}

If different declarations have been given for left and right pages,the user agent must honor these declarations even if the user agentdoes not transfer the page boxes to left and right sheets (e.g., aprinter that only prints single-sided).

Authors may also specify style for the first page of a documentwith the:first pseudo-class:

Example(s):

@page { margin: 2cm } /* All margins set to 2cm */@page :first {  margin-top: 10cm    /* Top margin on first page 10cm */}

Properties specified in a :left or :right @page rule overridethose specified in an @page rule that has no pseudo-class specified.Properties specified in a :first @page rule override those specifiedin :left or :right @page rules.

If aforced break occurs before the firstgenerated box, it is undefined in CSS 2.1 whether ':first'applies to the blank page before the break or to the page after it.

Margin declarations on left, right, and first pages may result indifferentpage area widths. To simplifyimplementations, user agents may use a single page area widthon left, right, and first pages. In this case, the page area widthof the first page should be used.

13.2.3Content outside the page box

When formatting content in the page model, some content may end upoutside the current page box. For example, an element whose'white-space' property has thevalue 'pre' may generate a box that is wider than the page box. Asanother example, when boxes are positioned absolutely or relatively,they may end up in "inconvenient" locations. For example, images maybe placed on the edge of the page box or 100,000 meters below the pagebox.

The exact formatting of such elements lies outside the scope ofthis specification. However, we recommend that authors and user agentsobserve the following general principles concerning content outsidethe page box:

13.3Page breaks

This section describes page breaks in CSS 2.1. Fiveproperties indicate where the user agent may or should break pages,and on what page (left or right) the subsequent content should resume.Each page break ends layout in the currentpagebox and causes remaining pieces of thedocument tree to be laid out in a newpage box.

13.3.1Page break properties:'page-break-before','page-break-after','page-break-inside'

'page-break-before'
Value:  auto | always | avoid | left | right |inherit
Initial:  auto
Applies to:  block-level elements (but see text)
Inherited:  no
Percentages:  N/A
Media:  visual,paged
Computed value:  as specified
'page-break-after'
Value:  auto | always | avoid | left | right |inherit
Initial:  auto
Applies to:  block-level elements (but see text)
Inherited:  no
Percentages:  N/A
Media:  visual,paged
Computed value:  as specified
'page-break-inside'
Value:  avoid | auto |inherit
Initial:  auto
Applies to:  block-level elements (but see text)
Inherited:  no
Percentages:  N/A
Media:  visual,paged
Computed value:  as specified

Values for these properties have the following meanings:

auto
Neither force nor forbid a page break before (after, inside) the generated box.
always
Always force a page break before (after) the generated box.
avoid
Avoid a page break before (after, inside) the generated box.
left
Force one or two page breaks before(after) the generated box so that the next page is formatted as a left page.
right
Force one or two page breaks before (after) the generatedbox so that the next page is formatted as a right page.

A conforming user agentmay interpret the values 'left' and 'right' as 'always'.

A potential page break location is typically under the influenceof the parent element's'page-break-inside'property, the'page-break-after' propertyof the preceding element, and the'page-break-before' propertyof the following element. When these properties have values otherthan 'auto', the values 'always', 'left', and 'right' take precedenceover 'avoid'.

User Agents must apply these properties to block-level elementsin the normal flow of the root element. User agents may also applythese properties to other elements, e.g., 'table-row' elements.

When a page break splits a box, the box's margins, borders, andpadding have no visual effect where the split occurs.

13.3.2Breaks inside elements:'orphans','widows'

'orphans'
Value:  <integer> |inherit
Initial:  2
Applies to:  block container elements
Inherited:  yes
Percentages:  N/A
Media:  visual,paged
Computed value:  as specified
'widows'
Value:  <integer> |inherit
Initial:  2
Applies to:  block container elements
Inherited:  yes
Percentages:  N/A
Media:  visual,paged
Computed value:  as specified

The'orphans' propertyspecifies the minimum number of lines in a block container that must be leftat the bottom of a page. The'widows' property specifies the minimumnumber of lines in a block container that must be left at the top of a page.Examples of how they are used to control page breaks are given below.

Only positive values are allowed.

For information about paragraph formatting, please consult thesection online boxes.

13.3.3Allowed page breaks

In the normal flow, page breaks can occur at the following places:

  1. In the vertical margin between block-level boxes. When an unforced pagebreak occurs here, theusedvalues of the relevant'margin-top' and'margin-bottom' properties areset to '0'. When a forced page break occurs here, the used value ofthe relevant'margin-bottom' property is setto '0'; the relevant'margin-top' used value may eitherbe set to '0' or retained.
  2. Betweenline boxesinside ablock container box.
  3. Between the content edge of a block container box and the outer edges of itschild content (margin edges of block-level children or line box edgesfor inline-level children) if there is a (non-zero) gap between them.

Note: It is expected that CSS3 will specify that therelevant 'margin-top' applies (i.e., is not set to '0') after a forcedpage break.

These breaks are subject to the following rules:

If the above does not provide enough break points to keep contentfrom overflowing the page boxes, then rules A, B and D are dropped inorder to find additional breakpoints.

If that still does not lead to sufficient break points, ruleC is dropped as well, to find still more break points.

13.3.4Forced page breaks

A page breakmust occur at (1) if, among the'page-break-after' and'page-break-before'properties of all the elements generating boxes that meet at thismargin, there is at least one with the value 'always', 'left', or'right'.

13.3.5"Best" page breaks

CSS 2.1 doesnot define which of a set of allowed page breaksmust be used; CSS 2.1 does not forbid a user agent from breaking at everypossible break point, or not to break at all. But CSS 2.1 does recommendthat user agents observe the following heuristics (while recognizingthat they are sometimes contradictory):

Example(s):

Suppose, for example, that the style sheet contains 'orphans: 4', 'widows: 2', andthere are 20 lines (line boxes)available at the bottom of the current page:

Now suppose that'orphans' is'10','widows' is '20', and there are 8 lines available at the bottom of the current page:

13.4Cascading in the page context

Declarations in thepage context obeythecascade just like normal CSSdeclarations.

Example(s):

Consider the following example:

@page {  margin-left: 3cm;}@page :left {  margin-left: 4cm;}

Due to thehigherspecificity of the pseudo-class selector, the left margin on leftpages will be '4cm' and all other pages (i.e., the right pages) willhave a left margin of '3cm'.


previous  next  contents  properties  index  


[8]ページ先頭

©2009-2025 Movatter.jp