css3-page/Overview.src.html

Thu, 07 Mar 2013 17:13:37 +0100

author
Simon Sapin <simon.sapin@exyr.org>
date
Thu, 07 Mar 2013 17:13:37 +0100
changeset 7677
2a3f835f72e3
parent 7676
48ca1db78135
child 7681
b1294a270bbe
permissions
-rw-r--r--

[css3-page] Define the default stacking order of page-margin boxes.

WG resolution:
http://lists.w3.org/Archives/Public/www-style/2013Mar/0157.html
http://lists.w3.org/Archives/Public/www-style/2013Mar/0163.html

fantasai@213 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
fantasai@213 2 <html lang="en">
fantasai@213 3 <head>
fantasai@213 4 <title>
fantasai@215 5 CSS Paged Media Module Level 3
fantasai@213 6 </title>
fantasai@213 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
fantasai@213 8 <link href="../default.css" rel="stylesheet" type="text/css">
fantasai@213 9 <link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED.css">
fantasai@215 10 <style type="text/css">
fantasai@215 11 .keyword { font-weight:bold }
fantasai@213 12 .equation { padding: 2% }
fantasai@213 13 table.equation {text-align:center}
fantasai@213 14 td, th { vertical-align: top }
fantasai@213 15 pre { font-size: 1em; }
simon@6956 16
simon@6956 17 #margin-values { border-collapse: collapse; }
simon@6956 18 #margin-values td,
simon@6956 19 #margin-values th
simon@6956 20 {
simon@6956 21 padding: 0.2em;
fantasai@213 22 border: thin solid black;
fantasai@213 23 }
fantasai@213 24
fantasai@213 25 .property-list
fantasai@213 26 {
fantasai@213 27 border: 1px solid black;
fantasai@213 28 padding: .2em;
fantasai@213 29 margin-top: 2em;
fantasai@213 30 }
simon@6956 31
fantasai@213 32 .property-list td
fantasai@213 33 {
fantasai@213 34 border: 1px solid black;
fantasai@213 35 padding: .1em;
fantasai@213 36 }
fantasai@213 37
simon@6956 38 .editorial
simon@6956 39 {
simon@6956 40 display: block;
fantasai@213 41 font-family: arial, helvetica, sans-serif;
fantasai@213 42 font-size: 80%;
simon@6956 43 margin-left: .5in;
simon@6956 44 margin-right: 1in ;
fantasai@213 45 padding: 0.125in;
fantasai@213 46 background: #FFFFDD ;
fantasai@213 47 }
simon@6956 48
fantasai@213 49 .editorial:after { content: "Ed."}
simon@6956 50 .RFC2119
simon@6956 51 {
simon@6956 52 text-transform: lowercase;
simon@6956 53 font-style: italic
fantasai@213 54 }
simon@6956 55
simon@6956 56 em em.RFC2119
fantasai@213 57 {
simon@6956 58 text-transform: lowercase;
simon@6956 59 font-style: normal
simon@6956 60 }
simon@6956 61
simon@6956 62 table.page-sizes
simon@6956 63 {
simon@6956 64 border: thin solid;
fantasai@213 65 margin-top: 1.5em;
fantasai@213 66 }
simon@6956 67 table.page-sizes td
simon@6956 68 {
simon@6956 69 border: thin solid;
fantasai@213 70 padding: .5em;
fantasai@213 71 }
simon@6956 72 table.page-sizes th
simon@6956 73 {
simon@6956 74 border: thin solid;
simon@6956 75 padding: .5em;
fantasai@213 76 background: #ffffaa;
fantasai@213 77 }
fantasai@213 78
fantasai@213 79 </style>
fantasai@213 80 </head>
tantek@7536 81 <body class="h-entry">
fantasai@213 82 <div>
fantasai@213 83 <div class="head">
fantasai@213 84 <!--logo-->
tantek@7536 85 <h1 class="p-name">CSS Paged Media Module Level 3</h1>
tantek@7536 86 <h2 class="no-num no-toc" id="w3c-working">[LONGSTATUS] <span class="dt-updated"><span class="value-title" title="[CDATE]">[DATE]</span></span></h2>
fantasai@213 87 <dl>
tantek@7536 88 <dt>This version:</dt> <dd><a class="u-url" href="http://dev.w3.org/csswg/css3-page/">http://dev.w3.org/csswg/css3-page/</a></dd>
tantek@7536 89 <!-- <dd><a class="u-url" href="[VERSION]">http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]</a></dd> -->
fantasai@213 90 <dt>Latest version:</dt> <dd><a href="http://www.w3.org/TR/css3-page">http://www.w3.org/TR/css3-page</a></dd>
simon@7552 91 <dt>Previous version:</dt> <dd><a rel="previous" href="http://www.w3.org/TR/2006/WD-css3-page-20061010/">http://www.w3.org/TR/2006/WD-css3-page-20061010/</a></dd>
tantek@7536 92 <dt>Issue Tracking:</dt>
tantek@7536 93 <dd><a rel="issues" href="http://www.w3.org/Style/CSS/Tracker/products/13">http://www.w3.org/Style/CSS/Tracker/products/13</a>
tantek@7536 94 <!-- or use the wiki:
tantek@7536 95 <dd><a rel="issues" href="http://wiki.csswg.org/spec/css3-page"
tantek@7536 96 >http://wiki.csswg.org/spec/css3-page</a></dd>
tantek@7536 97 -->
tantek@7536 98 <dt>Feedback:</dt>
tantek@7536 99 <dd><a href="mailto:www-style@w3.org?subject=%5B[SHORTNAME]%5D%20feedback"
simon@7552 100 >www-style@w3.org</a>
simon@7552 101 with subject line &ldquo;<kbd>[[SHORTNAME]]
tantek@7536 102 <var>&hellip; message topic &hellip;</var></kbd>&rdquo;
tantek@7536 103 (<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/"
tantek@7536 104 >archives</a>)
tantek@7536 105
simon@7552 106 <dt>Editors:</dt>
tantek@7536 107 <dd class="p-author h-card vcard">
simon@7552 108 <span class="p-name fn">Melinda Grant</span>,
tantek@7536 109 <span class="p-org org">Hewlett-Packard</span></dd>
tantek@7536 110 <dd class="p-author h-card vcard">
simon@7552 111 <span class="p-name fn">H&aring;kon Wium Lie</span>,
tantek@7536 112 <span class="p-org org">Opera Software</span></dd>
tantek@7536 113 <dd class="p-author h-card vcard">
simon@7552 114 <span class="p-name fn">Elika J. Etemad</span>,
tantek@7536 115 <span class="p-org org">Mozilla</span></dd>
tantek@7536 116 <dd class="p-author h-card vcard">
simon@7552 117 <span class="p-name fn">Simon Sapin</span>,
tantek@7536 118 <span class="p-org org">Kozea</span></dd>
fantasai@213 119 </dl>
fantasai@213 120
fantasai@213 121 <!--copyright-->
fantasai@213 122
fantasai@213 123 </div>
fantasai@213 124 <hr title="Separator for header">
fantasai@213 125
fantasai@213 126 <h2 class="no-num no-toc" id="abstract">Abstract</h2>
fantasai@213 127
tantek@7536 128 <p>
tantek@7536 129 <span class="p-summary">
tantek@7536 130 This module describes the page model that partitions a flow into pages. It
fantasai@5976 131 builds on the <a href="http://www.w3.org/TR/CSS21/box.html">Box model module</a> and introduces
fantasai@213 132 and defines the page model and paged media. It adds functionality for
fantasai@213 133 pagination, page margins, page size and orientation, headers and footers,
fantasai@213 134 widows and orphans, and image orientation. Finally it extends generated content
tantek@7536 135 to enable page numbering and running headers / footers. </span>
tantek@7536 136 </p>
fantasai@213 137
fantasai@213 138 <!-- "Status of this document" -->
fantasai@213 139
fantasai@213 140 <h2 class="no-num no-toc" id="status">Status of this Document</h2>
fantasai@213 141
fantasai@213 142 <!--status-->
fantasai@213 143
fantasai@213 144 <p>This document contains the <abbr title="Cascading Style Sheets">CSS3</abbr>
fantasai@213 145 Paged Media Module W3C Last Call <a href="/2005/10/Process-20051014/tr.html#RecsWD">Working Draft</a> of [DATE]. The
fantasai@213 146 Last Call period ends on <span class="fudge">TBD</span>.</p>
fantasai@213 147
fantasai@2094 148 <p>Expected next revision to this document is another LCWD, due to the
simon@7289 149 substantive changes to page-margin box sizing and other areas that are now
fantasai@2094 150 specified with more precision.</p>
fantasai@213 151
fantasai@213 152 <p>The <a href="lc2_issues.htm">Disposition of Comments</a>
fantasai@213 153 document contains the current issues list and responses to input received
fantasai@213 154 during this Last Call period.</p>
fantasai@213 155
fantasai@213 156 <h2 class="no-num no-toc" id="contents">Table of Contents</h2><!--begin-toc-->
fantasai@213 157 <!--end-toc-->
fantasai@213 158 <!-- "Introduction" -->
fantasai@213 159 <h2 id="intro">Introduction</h2>
fantasai@213 160
fantasai@213 161 <p>Paged media (e.g., paper, transparencies, photo album pages, pages
fantasai@213 162 displayed on computer screens as printed output simulations) differ from
fantasai@5976 163 <a href="http://www.w3.org/TR/CSS2/media.html#continuous-media-group">continuous media</a>
fantasai@213 164 in that the content of the document is split into one or more discrete
fantasai@213 165 static display surfaces. To handle pages, CSS3 Paged Media describes how:</p>
fantasai@213 166
fantasai@213 167 <ul>
fantasai@213 168 <li><a href="#page-breaks">page breaks</a> are created and avoided;</li>
fantasai@213 169 <li>the page properties such as size, orientation, margins, border, and
fantasai@213 170 padding are specified;</li>
fantasai@213 171 <li>headers and footers are established within the page margins;</li>
fantasai@213 172 <li>content such as page counters are placed in the headers and footers; and</li>
fantasai@213 173 <li>orphans and widows can be controlled.</li>
fantasai@213 174 </ul>
fantasai@213 175
fantasai@213 176 <p>This module defines a <a href="#page-model">page model</a> that specifies how a
fantasai@552 177 document is formatted within a rectangular area, called the
fantasai@552 178 <a href="#page-box-page-rule">page box</a>, that has finite width and height.
fantasai@522 179
fantasai@527 180 <p>Although CSS3 does not specify how user agents transfer page boxes to sheets,
fantasai@527 181 it does include certain mechanisms for telling user agents about the intended
fantasai@527 182 page sheet <a href="#page-size">size and orientation</a>. In the general case,
fantasai@527 183 CSS3 assumes that one page box will be transferred to one surface of similar
fantasai@527 184 size.</p>
fantasai@522 185
fantasai@1052 186 <p>All properties defined in this specification also accept the
fantasai@1052 187 <a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
fantasai@1052 188 keyword as their value, but for readability it has not been listed explicitly.
fantasai@522 189
fantasai@527 190 <h2 id="conformance">Conformance</h2>
fantasai@522 191
fantasai@685 192 <p>All of the text in this specification is normative except sections
fantasai@685 193 explicitly marked as non-normative, examples, and notes. The keywords
fantasai@685 194 "<em class="RFC2119">MUST</em>", "<em class="RFC2119">SHALL</em>",
fantasai@527 195 "<em class="RFC2119">MUST NOT</em>", "<em class="RFC2119">SHALL NOT</em>",
fantasai@527 196 "<em class="RFC2119">REQUIRED</em>", "<em class="RFC2119">SHOULD</em>",
fantasai@527 197 "<em class="RFC2119">SHOULD NOT</em>", "<em class="RFC2119">RECOMMENDED</em>",
fantasai@527 198 "<em class="RFC2119">MAY</em>", and "<em class="RFC2119">OPTIONAL</em>" when
fantasai@527 199 used in this document are to be interpreted as described in <cite>RFC
fantasai@527 200 2119</cite> [[!RFC2119]]. However, for readability, these words do not appear
fantasai@685 201 in all uppercase letters in this specification.</p>
fantasai@522 202
fantasai@527 203 <p>Examples in this specification are introduced with the words "for example"
fantasai@527 204 or are set apart from the normative text with <code>class="example"</code>,
fantasai@527 205 like this:
fantasai@522 206
fantasai@527 207 <div class="example">
fantasai@527 208 <p>This is an example of an informative example.</p>
fantasai@527 209 </div>
fantasai@523 210
fantasai@527 211 <p>Informative notes begin with the word "Note" and are set apart from the
fantasai@527 212 normative text with <code>class="note"</code>, like this:
fantasai@523 213
fantasai@527 214 <p class="note">Note, this is an informative note.</p>
fantasai@527 215
fantasai@564 216 <h2 id="page-terms">Page Terminology</h2>
fantasai@213 217
fantasai@213 218 <p>The following terminology and accompanying diagrams help to describe the
fantasai@523 219 page model:</p>
fantasai@213 220
fantasai@213 221 <dl>
fantasai@213 222 <dt id="page-sheet">Page sheet</dt>
fantasai@213 223 <dd><img src="PageSheet.png" style="float: right;" alt="The corner of a page sheet with the non-printable area at the edge and printable area inside it"
fantasai@213 224 height="148" width="194">The page sheet is one surface of the physical
fantasai@213 225 medium. The illustration to the right shows a representation of the upper-left
fantasai@213 226 corner of a page sheet.</dd>
fantasai@523 227
fantasai@213 228 <dt id="printable-area">Printable and non-printable areas</dt>
fantasai@213 229 <dd>The non-printable area is the area of a page sheet that a physical device such
fantasai@213 230 as a printer is not capable of marking reliably, usually due to the printer's
fantasai@213 231 paper handling mechanism. This value is printer dependent and is usually a
fantasai@213 232 small region along each edge of the page sheet. The printable area is the area
fantasai@213 233 of page sheet that a printer <em>is</em> capable of marking reliably. The size
fantasai@213 234 of the printable area is the size of the page sheet reduced by the size of the
fantasai@213 235 non-printable area. A user agent may not know the dimensions of this area for a
fantasai@213 236 particular printing device; but when its dimensions are known, user agents
fantasai@213 237 <em class="RFC2119">MAY</em> adjust the formatting of the document so that
fantasai@213 238 content falls within the printable area. How this adjustment is accomplished is
fantasai@5987 239 device dependent within the constraints expressed in the sections
fantasai@5987 240 <a href="#renderingpages">Rendering page boxes that do not fit a page sheet</a> and
fantasai@213 241 <a href="#content-outside-box">Content outside the page box</a>.</dd>
fantasai@523 242
fantasai@523 243 <dt id="page-orientation">Page Orientation</dt>
fantasai@523 244 <dd>The page orientation is defined by comparing the length of the edges of a
fantasai@523 245 <a href="#page-box">page box</a>. The page box is a rectangle with two
fantasai@523 246 perpendicular edges called the long edge and the short edge. The length of the
fantasai@523 247 long edge is always greater than or equal to the length of the short edge. When
fantasai@523 248 the page box is square, the two edges are of the same length and either can be
fantasai@523 249 used as the long edge with the other being the short edge. This specification
fantasai@523 250 defines page orientations of 'portrait' and 'landscape'.</dd>
fantasai@523 251
fantasai@523 252 <dt id="portrait">Portrait Orientation</dt>
fantasai@523 253 <dd>A portrait page's height is greater than or equal to its width. Horizontal
fantasai@523 254 elements are parallel to the short edge and vertical elements to the long edge.</dd>
fantasai@523 255
fantasai@523 256 <dt id="landscape">Landscape Orientation</dt>
fantasai@523 257 <dd>A landscape page's width is greater than or equal to its height. Horizontal
fantasai@1136 258 elements are parallel to the long edge and vertical elements to the short edge.
fantasai@1136 259 <span class="note">Note that CSS3 makes no distinction between landscape and
fantasai@1136 260 reverse-landscape orientations. However, future versions of CSS may do so.
fantasai@1136 261 UAs should consider, when formatting for duplexed printing, the binding edge,
fantasai@1136 262 page progression, and ease of reading when choosing between landscape and
fantasai@1136 263 reverse-landscape renderings.</span>
fantasai@1136 264 </dd>
fantasai@523 265
fantasai@523 266 <dt id="duplex-printing">Duplex Printing</dt>
fantasai@523 267 <dd>Duplex printing prints one page box per side of a page sheet and uses both
fantasai@523 268 sides of the page sheet. This module provides no ability to specify whether a
fantasai@523 269 document is duplex printed, but the concept of left and right pages is based on
fantasai@523 270 the assumption that the document is duplex printed, regardless of whether or
fantasai@523 271 not it actually is.</dd>
fantasai@523 272
fantasai@523 273 <dt id="binding-edge">Binding Edge</dt>
fantasai@523 274 <dd>The binding edge is the edge of the page box that is toward the binding if the
fantasai@523 275 material is bound. The binding edge often has a larger margin than the opposite
fantasai@523 276 edge to provide for the space used by the binding. The binding edge can be any
fantasai@523 277 of the four edges. However, page sheets are customarily bound so that the
fantasai@523 278 binding edge of page boxes with portrait orientation is vertical. This module
fantasai@523 279 provides no method to specify the binding edge. In duplex printing, the binding
fantasai@523 280 edge is on opposite sides of the page box for the left and right pages.</dd>
fantasai@523 281
fantasai@523 282 <dt id="facing-pages">Facing Pages</dt>
fantasai@523 283 <dd>Facing pages are two sequential pages such that when the document is duplex
fantasai@523 284 printed they are on separate sheets of paper. Typically, the earlier page will
fantasai@523 285 be the back side of one sheet and the later page will be the front side of
fantasai@523 286 another. They are usually laid out so that the binding edges of facing pages
fantasai@523 287 are vertical and adjacent when the pages are placed in their normal reading
fantasai@523 288 orientation.</dd>
fantasai@526 289
fantasai@526 290 <dt id="left-page">Left Page</dt>
fantasai@526 291 <dd>A page that would be on the left if it is part of a pair of facing pages as
fantasai@526 292 typically laid out. Page layouts for documents using a left-to-right page
fantasai@526 293 progression have the earlier of the facing pages on the left. Rules specific to
simon@7554 294 the left page can be specified using the <span class="css">':left'</span>
simon@7554 295 <i>page selector</i>.
simon@7554 296 </dd>
simon@6956 297
fantasai@526 298 <dt id="right-page">Right Page</dt>
fantasai@526 299 <dd>A page that would be on the right if it is part of a pair of facing pages as
fantasai@526 300 typically laid out. Page layouts for documents using a right-to-left page
fantasai@526 301 progression have the earlier of the facing pages on the right. Rules specific
fantasai@526 302 to the right page can be specified using the <span class="css">':right'</span>
simon@7554 303 <i>page selector</i>.
simon@7554 304 </dd>
fantasai@213 305 </dl>
fantasai@213 306
fantasai@564 307
fantasai@564 308 <h2 id="page-box-page-rule">The Page Model</h2>
fantasai@564 309
fantasai@564 310 <p>In the paged media formatting model, the document is transferred into one
fantasai@564 311 or more page boxes. The <dfn id="page-box">page box</dfn> is a specialized CSS
fantasai@564 312 box that maps to a rectangular print media surface, such as a page of paper.
fantasai@5976 313 It is roughly analogous to the <a href="http://www.w3.org/TR/CSS21/visuren.html#viewport">viewport</a>.
fantasai@564 314 <img src="PageBox.png" style="float: right;" alt="" height="266" width="267">
fantasai@564 315
fantasai@5976 316 <p>As with other CSS <a href="http://www.w3.org/TR/CSS21/box.html">boxes</a>, a page box
fantasai@3574 317 consists of margin, border, padding, and content areas. The content and
fantasai@3574 318 margin areas of a page box have special functions:</p>
fantasai@564 319
fantasai@564 320 <ul>
fantasai@564 321 <li>The content area of a page box is called the <dfn id="page-area">page
fantasai@564 322 area</dfn>. The content of the document is flowed into one or more page boxes.
fantasai@564 323 The page area acts as a container for all the boxes generated by the root
fantasai@564 324 element and its descendants that are laid out within a given page box. The
fantasai@564 325 edges of the page area on the first page establish the rectangle that is the
fantasai@5976 326 initial <a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">containing block</a>
fantasai@564 327 of the document.</li>
simon@7289 328 <li>The margin area of a page box is divided into
simon@7289 329 16 <dfn>page-margin boxes</dfn>.
simon@7289 330 Each page-margin box has its own margin, border, padding and content areas.
simon@7289 331 Page-margin boxes are typically used to display running headers and footers.</li>
fantasai@564 332 </ul>
fantasai@564 333
fantasai@5973 334 <p>The properties of a <i>page box</i> are determined by properties
fantasai@5976 335 <a href="http://www.w3.org/TR/CSS21/syndata.html#declaration">declared</a> within the
fantasai@5973 336 <i>page context</i>, which is the
fantasai@5976 337 <a href="http://www.w3.org/TR/CSS21/syndata.html#x14">declaration block</a> of the
simon@7289 338 <code>@page</code> rule. Similarly the properties of a <i>page-margin box</i>
fantasai@5973 339 are determined by properties declared within its <i>margin context</i>.
fantasai@5973 340 Declarations in the page context can affect the page box and/or inherit
simon@7289 341 to the page-margin boxes, but they do not apply to or inherit into the
fantasai@564 342 document's root element or other content.</p>
fantasai@564 343
fantasai@5973 344 <p>The <i>containing block</i> of the page box is specified using the 'size'
fantasai@5973 345 property in the <i>page context</i>. The width and horizontal margins
fantasai@5973 346 of the page box are then calculated exactly as for a
fantasai@5973 347 <a href="http://www.w3.org/TR/CSS21/visudet.html#blockwidth">non-replaced
fantasai@5973 348 block element in normal flow</a>. [[!CSS21]] The height and vertical margins
fantasai@5973 349 of the page box are calculated analogously (instead of using the block height
fantasai@5973 350 formulas). In both cases if the values are over-constrained, instead of
fantasai@5973 351 ignoring any margins, the containing block is resized to coincide with the
fantasai@5973 352 margin edges of the page box.
fantasai@5973 353
fantasai@6061 354 <h3 id="painting">
fantasai@6061 355 Page Backgrounds and Painting Order</h3>
fantasai@6061 356
fantasai@6061 357 <p>When drawing a page of content, the page layers are painted in the
fantasai@6061 358 following painting order (bottommost first):
fantasai@6061 359
fantasai@6061 360 <ol>
fantasai@6061 361 <li>page background
fantasai@6061 362 <li>document canvas
fantasai@6061 363 <li>page borders
fantasai@6061 364 <li>document contents
simon@7289 365 <li>page-margin boxes
fantasai@6061 366 </ol>
fantasai@6061 367
fantasai@6061 368 <p>In the page model, the page background behaves similar to the root background:
fantasai@6061 369 its <a href="http://www.w3.org/TR/css3-background/#background-painting-area"><i>background painting area</i></a>
fantasai@7443 370 is the entire page box, including its margins (regardless of 'background-clip').
fantasai@6065 371 Page backgrounds are anchored within the page box's padding area by default
fantasai@6061 372 (and honor 'background-origin' if the UA supports [[!CSS3BG]]).
fantasai@6061 373 However if 'background-attachment' is ''fixed''
fantasai@6061 374 then the image is positioned relative to the page box including its margins
fantasai@6061 375 (i.e. the <a href="http://www.w3.org/TR/css3-background/#background-positioning-area"><i>background positioning area</i></a>,
fantasai@6061 376 like the <i>background painting area</i>, is the page's margin box).
fantasai@6061 377
fantasai@6061 378 <p>The document canvas background is drawn as the page box's background:
fantasai@6065 379 by default its <i>background painting area</i> covers the page box's border box,
fantasai@6064 380 and for UAs that support [[!CSS3BG]], follows the 'background-clip' value specified on the root element.
fantasai@6061 381 It remains, however, positioned with respect to the root element
fantasai@6061 382 or page area as usual.
fantasai@6061 383
simon@7676 384 <p>The 'z-index' property applies to page-margin boxes.
simon@7289 385 With respect to the page-margin boxes,
fantasai@6061 386 the document canvas, page borders, and all of the document contents
fantasai@6061 387 are treated as a single element with a <code>z-index</code> value of '0':
simon@7289 388 the page-margin boxes never interleave with parts of the document content
fantasai@6061 389 or between the content and the canvas.
fantasai@6061 390 They may only paint in front of the document content or behind the document canvas.
fantasai@6061 391 The page background is always painted underneath everything else.
simon@7289 392 Since the <code>position</code> property does not apply to page-margin boxes,
simon@7289 393 <code>z-index</code> always affects page-margin boxes
simon@7289 394 as if they were positioned elements
simon@7289 395 regardless of the <code>position</code> property's value.
fantasai@6061 396
fantasai@6061 397 <p>The default painting order,
fantasai@6061 398 or <a href="http://www.w3.org/TR/CSS21/zindex.html">CSS2.1 Appendix E</a> "tree order",
simon@7677 399 of page-margin boxes with respect to each other is as follows:
simon@7677 400
simon@7677 401 <ol>
simon@7677 402 <li>''@top-left-corner''
simon@7677 403 <li>''@top-left''
simon@7677 404 <li>''@top-center''
simon@7677 405 <li>''@top-right''
simon@7677 406 <li>''@top-right-corner''
simon@7677 407
simon@7677 408 <li>''@right-top''
simon@7677 409 <li>''@right-middle''
simon@7677 410 <li>''@right-bottom''
simon@7677 411
simon@7677 412 <li>''@bottom-right-corner''
simon@7677 413 <li>''@bottom-right''
simon@7677 414 <li>''@bottom-center''
simon@7677 415 <li>''@bottom-left''
simon@7677 416 <li>''@bottom-left-corner''
simon@7677 417
simon@7677 418 <li>''@left-bottom''
simon@7677 419 <li>''@left-middle''
simon@7677 420 <li>''@left-top''
simon@7677 421 </ol>
simon@7677 422
simon@7677 423 <p class=note>
simon@7677 424 Start with ''@top-left-corner'', then go clockwise.
simon@7677 425 This order is arbitrary but can be overridden with 'z-index'.
simon@7677 426 It only has a visible effect when page-margin boxes overlap,
simon@7677 427 which should not happen in most cases.
fantasai@5973 428
fantasai@528 429 <h3 id="content-outside-box">Content outside the page box</h3>
fantasai@528 430
fantasai@528 431 <p>When formatting content in the page model, some content may end up outside the
fantasai@1134 432 page box. For example, an element whose 'white-space' property has the value
fantasai@1134 433 'pre' can generate a box that is wider than the page box. As another example,
fantasai@1134 434 when boxes are positioned absolutely or relatively, they may end up in
fantasai@1134 435 "inconvenient" locations. For example, images may be placed on the edge of
fantasai@1134 436 the page box or 100,000 meters below the page box. </p>
fantasai@528 437
fantasai@528 438 <p>A specification for the exact formatting of such elements lies outside the
fantasai@528 439 scope of this document. However, it is recommended that authors and user agents
fantasai@528 440 observe the following general principles concerning content outside the page
fantasai@528 441 box:</p>
fantasai@528 442
fantasai@528 443 <ul>
fantasai@1134 444 <li><p>Content should be allowed slightly beyond the page box to allow pages
fantasai@1134 445 to "bleed".
fantasai@565 446 <li><p>User agents <em class="RFC2119">SHOULD</em> avoid generating a large
fantasai@565 447 number of content-empty pages to honor the positioning of elements (e.g.,
fantasai@565 448 printing 100 blank pages is probably neither the author's nor the user's
fantasai@565 449 intent).
fantasai@565 450 A <dfn id="content-empty">Content-empty page</dfn> is a page box whose page
fantasai@565 451 area contains no printable content other than backgrounds and/or borders. A
fantasai@565 452 page box whose page area contains generated content, or content whose
fantasai@565 453 visibility is 'hidden', or invisible content such as a zero-width space is
fantasai@565 454 not a content-empty page. On the other hand, a page containing only a
simon@7289 455 background and/or borders and/or page-margin box content <em>is</em> a
fantasai@565 456 content-empty page.
fantasai@565 457 <p class="note">Note, however, that generating a small number of empty page
fantasai@565 458 boxes is sometimes necessary to honor the <span class="css">'left'</span> and
simon@7495 459 <span class="css">'right'</span> values for <span class="property">'break-before'</span>
simon@7495 460 and <span class="property">'break-after'</span>.</li>
fantasai@528 461
fantasai@565 462 <li><p>Authors <em class="RFC2119">SHOULD NOT</em> position elements in
fantasai@565 463 inconvenient locations just to avoid rendering them. Instead:
fantasai@565 464 <ul>
fantasai@565 465 <li>To suppress box generation entirely, set the <span class="property">'display'</span> property to <span class="css">'none'</span>.</li>
fantasai@565 466 <li>To make a box invisible, set the <span class="property">'visibility'</span>
fantasai@565 467 property.</li>
fantasai@565 468 </ul></li>
fantasai@565 469 <li><p>This specification does not define how boxes positioned outside the page
fantasai@565 470 box are handled. Possibilities include discarding them or creating page boxes
fantasai@565 471 for them at the end of the document.</li>
fantasai@565 472 </ul>
fantasai@528 473
fantasai@528 474 <h3 id="progression">Page Progression</h3>
fantasai@213 475
fantasai@526 476 <p>CSS distinguishes between left pages and right pages on all documents,
fantasai@526 477 whether they are printed duplex or not. Each left page is followed by a
fantasai@526 478 right page and vice versa. Left and right pages can be styled differently
fantasai@526 479 with the <a href="#left-right-first"><code>:left</code> and <code>:right</code>
fantasai@526 480 pseudo-classes</a>.
fantasai@213 481
fantasai@526 482 <p>Whether the first page of a document is a left page or a right page
fantasai@526 483 depends on the page progression of the document. The <dfn>page progression</dfn>
fantasai@526 484 is the direction in which the printed pages of a document would be sequenced
fantasai@557 485 when laid out side-to-side. For example, English and horizontally-set Japanese
fantasai@557 486 typically progress from left to right, whereas Arabic and vertically-set
fantasai@5987 487 Japanese pages typically progress from right to left. In documents with
fantasai@557 488 a left-to-right page progression the first page of the document is a right
fantasai@557 489 page, and vice versa.</p>
fantasai@213 490
fantasai@526 491 <p>The page progression direction is determined as follows:</p>
fantasai@213 492
fantasai@526 493 <ul>
fantasai@526 494 <li>If text is laid out in horizontal lines, the page progression is the
fantasai@526 495 same as the inline progression.</li>
fantasai@526 496 <li>If text is laid out in vertical lines, the page progression is the
fantasai@526 497 same as the block progression.</li>
fantasai@526 498 </ul>
fantasai@526 499
fantasai@5975 500 <p>If the UA supports the 'direction' and 'writing-mode' properties
fantasai@5975 501 from the CSS 3 Writing Modes Module [[CSS3-WRITING-MODES]], it must
fantasai@5975 502 <a href="http://www.w3.org/TR/css3-writing-modes/#page-direction">determine</a>
fantasai@526 503 whether the first page is a left or right page from the values of those
fantasai@526 504 properties on the root element.</p>
fantasai@526 505
fantasai@7437 506 <p>
fantasai@7437 507 To explicitly force a document to begin printing on a left or right page,
fantasai@7437 508 authors can specify a <a href="http://www.w3.org/TR/css3-break/#break-before">'break-before'</a> value
fantasai@7437 509 that that propagates a page break to the root. [[!CSS3-BREAK]]
fantasai@7437 510 The UA must suppress the first (empty) page(s) in this case
simon@7554 511 (and the <code>:first</code> pseudo-class matches the first printed page).
fantasai@213 512
simon@7334 513 <div class="example">
simon@7334 514 <pre>
simon@7495 515 html { break-before: always }
simon@7334 516 </pre>
simon@7334 517
simon@7334 518 <p>
simon@7334 519 For an HTML document with a left-to-right page progression,
simon@7334 520 the above style rule will cause the first page of the document
simon@7334 521 to print on a ':left' page
simon@7334 522 </p>
simon@7334 523
simon@7334 524 <pre>
simon@7495 525 html { break-before: left }
simon@7334 526 </pre>
simon@7334 527
simon@7334 528 <p>
simon@7334 529 For an HTML document,
simon@7334 530 the above style rule will cause the first page of the document
simon@7334 531 to print on a ':left' page,
simon@7334 532 regardless of the page progression.
simon@7334 533 </p>
simon@7334 534 </div>
simon@7334 535
fantasai@528 536 <h2 id="page-selector-and-context">Page Selectors and the Page Context</h2>
fantasai@528 537
fantasai@568 538 <h3 id="at-page-rule">The @page Rule</h3>
fantasai@568 539
fantasai@557 540 <p>Authors can specify various aspects of a page box, such as its dimensions,
simon@7290 541 orientation, and margins, within an <span class="css">@page</span> rule.
simon@7500 542 ''@page'' rules are allowed at the top-level of a stylesheet,
simon@7500 543 as well as wherever
simon@7500 544 <a href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">rule-sets</a>
simon@7500 545 are allowed.
simon@7290 546 An <span class="css">@page</span> rule consists of
simon@7290 547 the keyword <span class="css">'@page'</span>,
simon@7290 548 an <em class="RFC2119">OPTIONAL</em> comma-separated list of
simon@7554 549 <a href="#page-selectors">page selectors</a>
simon@7290 550 and a block of declarations
simon@7290 551 (said to be in the <dfn id="page-context">page context</dfn>).
simon@7498 552 An ''@page'' rule can also contain other at-rules,
simon@7498 553 interleaved between declarations.
simon@7498 554 The current level of this specification
simon@7498 555 only allows <a href="#margin-at-rules">margin at-rules</a> inside ''@page''.
fantasai@528 556
simon@7554 557 <p>''@page'' rules without a selector list
simon@7554 558 are considered to have a single, empty selector.
simon@7554 559 ''@page'' rules apply to pages that <i>match</i>
simon@7554 560 at least one of their selectors.
simon@7456 561
simon@7554 562 <p>Properties declared within the page context apply to the page box.
fantasai@528 563
fantasai@528 564 <p>If an error is encountered during the processing of a declaration block within
fantasai@5976 565 a page or a margin context, the <a href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">Rules for handling parsing errors</a>
fantasai@528 566 apply; that is, valid declarations within the block are applied.</p>
fantasai@528 567
simon@7554 568
simon@7554 569 <h3 id="page-selectors">Page selectors</h3>
simon@7554 570
simon@7554 571 <p>A <dfn id="page-selector">page selector</dfn> is either:
simon@7554 572
simon@7554 573 <ul>
simon@7554 574 <li>one or more
simon@7554 575 <a href="http://www.w3.org/TR/CSS21/syndata.html#characters">ASCII case-insensitive</a>
simon@7554 576 <a href="#pseudo-classes">pseudo-classes</a>,
simon@7554 577 <li>a <a href="#using-named-pages">page type</a>
simon@7554 578 (a case-sensitive identifier)
simon@7554 579 followed by zero or more pseudo-classes.
simon@7554 580 </ul>
simon@7554 581
simon@7555 582 <p>
simon@7555 583 No whitespace is allowed between components of a selector.
simon@7555 584 The <i title="page_selector">page selector grammar</i>
simon@7555 585 and examples can be found below.
simon@7554 586
simon@7554 587 <p>A selector is said to <dfn>match</dfn> a given page if and only if
simon@7554 588 all of its components match the page.
simon@7554 589 Empty selectors (ie. ''@page'' rules without a selector) match every page.
simon@7554 590 <span class="note">Empty selectors have the weakest <i>specificity</i>.</span>
simon@7554 591
simon@7554 592 <p><a href="#using-named-pages">Page type</a> selectors <i>match</i>
simon@7554 593 pages of the named type generated by the 'page' property.
simon@7554 594 <span id="page-selector-syntax-restrict">
simon@7554 595 A page type name of ''auto''
simon@7554 596 (<a href="http://www.w3.org/TR/CSS21/syndata.html#characters">ASCII case-insensitive</a>)
simon@7554 597 does not make the rule invalid,
simon@7554 598 but <em class="RFC2119">MUST</em> never match.
simon@7554 599 </span>
simon@7554 600 Individual <a href="#pseudo-classes">pseudo-classes</a> are defined below.
simon@7554 601
simon@7554 602 <h4 id="pseudo-classes">
simon@7435 603 <a id="left-right-first"></a>
simon@7435 604 Page pseudo-classes: :left, :right, :first, and :blank
simon@7554 605 </h4>
fantasai@528 606
simon@7434 607 <p>
simon@7607 608 In addition to the optional <i>page name</i>,
simon@7607 609 ''@page'' rules can restrict which pages they apply to
simon@7607 610 with CSS pseudo-classes in their <i>page selector</i>.
simon@7607 611
simon@7607 612 <p>
simon@7434 613 When printing double-sided documents,
simon@7434 614 left and right pages are often formatted differently.
simon@7434 615 All pages are automatically classified by user agents
simon@7434 616 as either left pages or right pages,
simon@7434 617 based on <a href="#progression">page progression</a>.
simon@7554 618 The '':left'' and '':right'' pseudo-classes only <i>match</i>
simon@7554 619 left or right pages, respectively.
fantasai@566 620
fantasai@566 621 <div class="example">
fantasai@566 622 The following example creates left and right binding edges using these pseudo-classes:
fantasai@566 623 <pre>
fantasai@566 624 @page :left {
fantasai@566 625 margin-left: 3cm;
fantasai@566 626 margin-right: 4cm;
fantasai@566 627 }
fantasai@566 628
fantasai@566 629 @page :right {
fantasai@566 630 margin-left: 4cm;
fantasai@566 631 margin-right: 3cm;
fantasai@566 632 }
fantasai@566 633 </pre>
fantasai@566 634 </div>
fantasai@566 635
fantasai@566 636 <p>If different declarations have been given for left and right pages, the user
fantasai@566 637 agent <em class="RFC2119">MUST</em> honor these declarations even if the user
fantasai@566 638 agent does not transfer the page boxes to left and right sheets (i.e., a
fantasai@566 639 printer that only prints on one side of the medium must nevertheless produce
fantasai@566 640 correctly formatted output).</p>
fantasai@566 641
simon@7334 642 <div class="note">
simon@7334 643 <p>
simon@7334 644 <em><strong>Note.</strong>
simon@7334 645 Adding declarations to the <span class="css">':left'</span> or
simon@7334 646 <span class="css">':right'</span> pseudo-class
simon@7334 647 does not necessarily influence whether the document
simon@7334 648 comes out of the printer double- or single-sided
simon@7334 649 (which is outside the scope of this specification).</em>
simon@7334 650 </p>
simon@7334 651 </div>
simon@7334 652
simon@7554 653 <p>
simon@7554 654 The '':first'' pseudo-class only <i title="match">matches</i>
simon@7554 655 the first printed page of a document.
fantasai@566 656
fantasai@566 657 <div class="example">
fantasai@566 658 <pre>
fantasai@566 659 @page { margin: 2cm } /* All margins set to 2cm */
fantasai@566 660
fantasai@566 661 @page :first {
fantasai@566 662 margin-top: 10cm /* Top margin on first page 10cm */
fantasai@566 663 }
fantasai@566 664 </pre>
fantasai@566 665 </div>
fantasai@566 666
simon@7435 667 <p>
simon@7554 668 The '':blank'' pseudo-class only <i title="match">matches</i>
simon@7554 669 <i title="content-empty page">content-empty pages</i>
simon@7499 670 that appear as a result of
simon@7554 671 <a href="http://www.w3.org/TR/css3-break/#forced-breaks">forced page breaks</a>.
simon@7435 672
simon@7499 673 <div class="note">
simon@7499 674 <p>Only the ''left'', ''right'', ''recto'' and ''verso'' values
simon@7499 675 of the 'break-before' and 'break-after' properties
simon@7499 676 can generate pages that match '':blank''.
simon@7499 677 </div>
simon@7499 678
simon@7435 679 <div class="example">
simon@7435 680 <p>In this example, forced page break may occur before <code>h1</code> elements.
simon@7435 681 <pre>
simon@7495 682 h1 { break-before: left }
simon@7435 683
simon@7435 684 @page :blank {
simon@7435 685 @top-center { content: "This page is intentionally left blank" }
simon@7435 686 }
simon@7435 687 </pre>
simon@7435 688 </div>
simon@7435 689
simon@7435 690 <p>
simon@7554 691 A page matched by '':blank'' can also be matched
simon@7435 692 by other page pseudo-classes.
simon@7435 693
simon@7435 694 <div class="example">
simon@7435 695
simon@7435 696 <p>If headers have been specified on all right pages, a blank right
simon@7435 697 page will be matched by both <code>:blank</code>
simon@7435 698 and <code>:right</code>. Therefore, margin boxes set on right pages
simon@7435 699 will have to be removed unless they are wanted on blank pages. Here is
simon@7435 700 an example where the top center header is removed from blank pages,
simon@7435 701 while the page number remains:
simon@7435 702
simon@7435 703 <pre>
simon@7495 704 h1 { break-before: left }
simon@7435 705
simon@7435 706 @page :blank {
simon@7435 707 @top-center { content: none }
simon@7435 708 }
simon@7435 709
simon@7435 710 @page :right {
simon@7435 711 @top-center { content: "Preliminary edition" }
simon@7435 712 @bottom-center { content: counter(page) }
simon@7435 713 }
simon@7435 714 </pre>
simon@7435 715
simon@7554 716 <p>Due to the higher <i>specificity</i> of <code>:blank</code>
simon@7435 717 over <code>:right</code>, the top center header is removed even
simon@7435 718 if <code>content: none</code> comes before <code>content: "Preliminary
simon@7435 719 edition"</code>.
simon@7435 720
simon@7435 721 </div>
simon@7435 722
fantasai@566 723 <div class="note">
fantasai@566 724 <p><em><strong>Note.</strong> Future versions of CSS may include other page
fantasai@566 725 pseudo-classes.</em></p>
fantasai@566 726 </div>
fantasai@566 727
fantasai@566 728 <h3 id="syntax-page-selector">@page rule grammar</h3>
fantasai@566 729
fantasai@566 730 <p>The syntax for the @page rule is a specialization of the generic at-rule
fantasai@566 731 defined by CSS 2.1. This grammar extends the at-rule syntax to allow @page rules
fantasai@566 732 nested inside @media rules. User agents <em class="RFC2119">MUST</em> adhere
fantasai@528 733 to the following grammar:</p>
fantasai@528 734
fantasai@528 735 <p>See [[!CSS21]], Section 4.1.1 and Appendix G for the expansion of missing
fantasai@528 736 productions:</p>
fantasai@528 737 <p id="specializatons-of-ATKEYWORD">
fantasai@528 738 All new lexical tokens are specializations of the ATKEYWORD lexical token:</p>
fantasai@528 739 <pre class="lexical">
fantasai@528 740 PAGE_SYM ::= "@page"
fantasai@528 741 TOPLEFTCORNER_SYM ::= "@top-left-corner"
fantasai@528 742 TOPLEFT_SYM ::= "@top-left"
fantasai@528 743 TOPCENTER_SYM ::= "@top-center"
fantasai@528 744 TOPRIGHT_SYM ::= "@top-right"
fantasai@528 745 TOPRIGHTCORNER_SYM ::= "@top-right-corner"
simon@6956 746 BOTTOMLEFTCORNER_SYM ::= "@bottom-left-corner"
fantasai@528 747 BOTTOMLEFT_SYM ::= "@bottom-left"
fantasai@528 748 BOTTOMCENTER_SYM ::= "@bottom-center"
fantasai@528 749 BOTTOMRIGHT_SYM ::= "@bottom-right"
fantasai@528 750 BOTTOMRIGHTCORNER_SYM ::= "@bottom-right-corner"
fantasai@528 751 LEFTTOP_SYM ::= "@left-top"
fantasai@528 752 LEFTMIDDLE_SYM ::= "@left-middle"
fantasai@528 753 LEFTBOTTOM_SYM ::= "@left-bottom"
fantasai@528 754 RIGHTTOP_SYM ::= "@right-top"
fantasai@528 755 RIGHTMIDDLE_SYM ::= "@right-middle"
fantasai@528 756 RIGHTBOTTOM_SYM ::= "@right-bottom"
fantasai@528 757
simon@7554 758 <dfn>media</dfn> :
simon@7554 759 MEDIA_SYM S* medium [ COMMA S* medium ]* LBRACE S* [ <i>page_rule</i> | ruleset ]* '}' S*
fantasai@528 760 ;
fantasai@528 761
simon@7554 762 <dfn id="syntax-prod-page">page_rule</dfn> :
simon@7554 763 PAGE_SYM S* <i>page_selector_list</i> '{' S* <i>page_body</i> '}' S*
fantasai@528 764 ;
simon@7439 765
simon@7554 766 <dfn>page_selector_list</dfn> :
simon@7554 767 [ <i>page_selector</i> S* [ ',' <i>page_selector</i> S* ]* ]?
simon@7439 768 ;
simon@7439 769
simon@7554 770 <dfn>page_selector</dfn> :
simon@7554 771 <i>pseudo_page</i>+ | IDENT <i>pseudo_page</i>*
simon@7290 772 ;
simon@7554 773
simon@7554 774 <dfn id="syntax-prod-pseudo-page">pseudo_page</dfn> :
simon@7435 775 ':' [ "left" | "right" | "first" | "blank" ]
fantasai@528 776 ;
fantasai@528 777
simon@7554 778 <dfn>page_body</dfn> : /* Can be empty */
simon@7554 779 declaration? [ ';' S* <i>page_body</i> ]? |
simon@7554 780 <i>page_margin_box</i> <i>page_body</i>
fantasai@528 781 ;
fantasai@528 782
simon@7554 783 <dfn id="syntax-prod-margin">page_margin_box</dfn> :
simon@7554 784 <i>margin_sym</i> S* '{' S* declaration? [ ';' S* declaration? ]* '}' S*
simon@7554 785 ;
simon@7554 786
simon@7554 787 <dfn id="syntax-prod-margin-sym">margin_sym</dfn> :
simon@6956 788 TOPLEFTCORNER_SYM |
simon@6956 789 TOPLEFT_SYM |
simon@6956 790 TOPCENTER_SYM |
simon@6956 791 TOPRIGHT_SYM |
fantasai@528 792 TOPRIGHTCORNER_SYM |
simon@6956 793 BOTTOMLEFTCORNER_SYM |
simon@6956 794 BOTTOMLEFT_SYM |
simon@6956 795 BOTTOMCENTER_SYM |
fantasai@528 796 BOTTOMRIGHT_SYM |
fantasai@528 797 BOTTOMRIGHTCORNER_SYM |
fantasai@528 798 LEFTTOP_SYM |
fantasai@528 799 LEFTMIDDLE_SYM |
fantasai@528 800 LEFTBOTTOM_SYM |
fantasai@528 801 RIGHTTOP_SYM |
fantasai@528 802 RIGHTMIDDLE_SYM |
simon@6956 803 RIGHTBOTTOM_SYM
fantasai@528 804 ;
fantasai@528 805 </pre>
fantasai@1101 806
fantasai@528 807 <div class="example">
fantasai@528 808 <p>The following are examples of page selectors (declaration block intentionally
fantasai@528 809 left blank)</p>
fantasai@528 810 <pre>
fantasai@528 811 @page { ... }
fantasai@528 812 @page :left { ... }
fantasai@528 813 @page :right { ... }
fantasai@528 814 @page LandscapeTable { ... }
fantasai@528 815 @page CompanyLetterHead:first { ... } /* identifier and pseudo page. */
simon@7555 816 @page:first { ... }
simon@7555 817 @page toc, index { ... }
simon@7555 818 @page :blank:first { ... }
fantasai@528 819 </pre>
fantasai@528 820
simon@7289 821 <p>The following are examples of page-margin boxes
simon@7289 822 where the declaration blocks are intentionally left blank.</p>
fantasai@528 823 <pre>
fantasai@528 824 @page {
fantasai@528 825 @top-left { ... /* document name */ }
fantasai@528 826 @bottom-center { ... /* page number */}
fantasai@528 827 }
fantasai@528 828 @page :left { @left-middle { ... /* page number in left margin */ }}
fantasai@528 829 @page :right{ @right-middle { ... /* page number in right margins of right pages */}}
fantasai@528 830
fantasai@528 831 @page :left { @bottom-left-corner { ... /* left page numbers */ }}
fantasai@528 832 @page :right { @bottom-right-corner { ... /* right page numbers */ }}
fantasai@528 833 @page :first { @bottom-left-corner { ... /* empty footer on 1st page */ }
fantasai@528 834 @bottom-right-corner { ... /* empty footer */ } }
fantasai@528 835 </pre>
fantasai@528 836 </div>
fantasai@528 837
fantasai@528 838 <h3 id="cascading-and-page-context">Cascading in the page context</h3>
fantasai@528 839
fantasai@5976 840 <p>Declarations in page and margin contexts <a href="http://www.w3.org/TR/CSS21/cascade.html">cascade</a> just like declarations in <a href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">rule sets</a>.</p>
fantasai@528 841
simon@7554 842 <p>The <dfn>specificity</dfn> of page a selector is computed in a manner
simon@7554 843 analogous to the computations defined in
simon@7554 844 the <a href="http://www.w3.org/TR/CSS21/selector.html">Selectors</a> module:
simon@7513 845
fantasai@528 846 <ul>
simon@7554 847 <li>Count the number of page type names (= <var>f</var>)
simon@7572 848 <p class="note">
simon@7572 849 Given the syntax of page seletors, <var>f</var> can only ever be 0 or 1.
simon@7513 850 <li>Count the number of ':first' or ':blank' pseudo-classes (= <var>g</var>)
simon@7513 851 <li>Count the number of ':left' or ':right' pseudo-classes (= <var>h</var>)
fantasai@528 852 </ul>
fantasai@528 853
simon@7513 854 <p>
simon@7554 855 Specificities are compared by comparing the three components in order:
simon@7554 856 the specificity with <var>f</var> larger a value is more specific;
simon@7554 857 if the two <var>f</var> values are tied,
simon@7554 858 then the specificity with a larger <var>g</var> value is more specific;
simon@7554 859 if the two <var>g</var> values are also tied,
simon@7554 860 then the specificity with a larger <var>h</var> value is more specific;
simon@7554 861 if all the values are tied, the two specifities are equal.
simon@7513 862
simon@7513 863 <p>
simon@7513 864 Due to storage limitations,
simon@7513 865 implementations may have limitations on
simon@7513 866 the size of <var>f</var>, <var>g</var>, or <var>h</var>.
simon@7513 867 If so, values higher than the limit must be clamped to that limit,
simon@7513 868 and not overflow.
simon@7513 869
simon@7513 870 <p class="note">
simon@7554 871 Note: Each comma-separated selectors in the same ''@page'' rule
simon@7554 872 has its own specificity.
simon@7554 873
simon@7554 874 <p class="note">
simon@7554 875 Note: Repeated occurrances of the same pseudo-classes are allowed
simon@7513 876 and do increase specificity.
fantasai@528 877
fantasai@528 878 <div class="example">
fantasai@528 879
fantasai@528 880 <p>Some page specificity calculation examples follow:</p>
fantasai@528 881 <pre>
simon@7513 882 @page { } /* specificity = (0,0,0) */
simon@7513 883 @page :left { } /* specificity = (0,0,1) */
simon@7513 884 @page :first { } /* specificity = (0,1,0) */
simon@7513 885 @page artsy { } /* specificity = (1,0,0) */
simon@7513 886 @page artsy:left { } /* specificity = (1,0,1) */
simon@7513 887 @page artsy:first { } /* specificity = (1,1,0) */
fantasai@528 888 </pre>
fantasai@528 889 </div>
fantasai@528 890
fantasai@528 891 <div class="example">
fantasai@528 892
fantasai@528 893 <p>Consider the following usage example:</p>
fantasai@528 894 <pre>
fantasai@528 895 @page {
simon@7513 896 margin-left: 3cm;
fantasai@528 897 }
fantasai@528 898
fantasai@528 899 @page :left {
simon@7513 900 margin-left: 4cm;
fantasai@528 901 }
fantasai@528 902 </pre>
fantasai@528 903
simon@7513 904 <p>Due to the higher specificity of the pseudo-class selector,
simon@7513 905 the left margin on left pages will be 4cm and all other pages
simon@7513 906 (the right-facing pages) will have a left margin of 3cm.
fantasai@528 907 </div>
fantasai@528 908
fantasai@528 909 <div class="example">
fantasai@528 910 <p>In this example, the higher specificity of the green rules wins over the red
simon@7289 911 rule.
simon@7289 912 Therefore the first page will have blue text in the top-left page-margin box
simon@7289 913 and green text in the top-right page-margin box,
simon@7289 914 while subsequent pages will have red text in the page-margin boxes.</p>
fantasai@528 915 <pre>
fantasai@528 916 @page :first {
simon@7513 917 color: green;
fantasai@528 918
simon@7513 919 @top-left {
simon@7513 920 content: "foo";
simon@7513 921 color: blue;
simon@7513 922 }
simon@7513 923 @top-right {
simon@7513 924 content: "bar";
simon@7513 925 }
fantasai@528 926 }
fantasai@528 927
fantasai@528 928 @page { color: red;
simon@7513 929 @top-center {
simon@7513 930 content: "Page " counter(page);
fantasai@528 931 }
fantasai@528 932 }
fantasai@528 933 </pre>
fantasai@528 934 </div>
fantasai@528 935
fantasai@528 936 <div class="example">
fantasai@528 937
fantasai@528 938 <p>Page contexts cascade, so the following stylesheet would style pages with 25
simon@7289 939 millimeter margins and 14 point type in the page-margin boxes:</p>
fantasai@528 940 <pre>
fantasai@528 941 @page { margin: 25mm;}
fantasai@528 942 @page { font-size: 14pt;}
fantasai@528 943 </pre>
fantasai@528 944 </div>
fantasai@528 945
simon@7289 946 <h2 id="margin-boxes">Page-Margin Boxes</h2>
fantasai@528 947
fantasai@7450 948 <p>Page-margin boxes are boxes within the page margin that,
fantasai@7450 949 like pseudo-elements, can contain generated content.
fantasai@528 950
fantasai@7450 951 <p>Page-margin boxes can be used to create page headers and footers,
fantasai@7450 952 which are portions of the page set aside for supplementary information
fantasai@7450 953 such as the page number or document title.
fantasai@528 954
fantasai@7450 955 <div class="example">
fantasai@7450 956 <p>Typically, a <dfn>page header</dfn> is located at the top of the page
fantasai@7450 957 in documents with a predominately horizontal writing direction
fantasai@7450 958 and on the side opposite the <a href="#binding-edge">binding edge</a>
fantasai@7450 959 for documents with a predominately vertical writing direction.
fantasai@7450 960 One possible design of page headers for horizontally written documents uses the
fantasai@7450 961 ''@top-left-corner'', ''@top-left'', ''@top-center'', ''@top-right'' and ''@top-right-corner''
fantasai@7450 962 page-margin boxes.
fantasai@7450 963 Another design, for vertically written documents, could use the
simon@7455 964 ''@right-top'', ''@right-middle'', and ''@right-bottom'' page-margin boxes
fantasai@7450 965 for <a href="#right-page">right facing pages</a> and
fantasai@7450 966 ''@left-top'', ''@left-middle'', and ''@left-bottom''
fantasai@7450 967 for <a href="#left-page">left facing pages</a>.
simon@7455 968
fantasai@7450 969 <p>The <dfn>page footer</dfn> is typically at
fantasai@7450 970 the opposite end of the page from the page header.
fantasai@7450 971 For example, the design of a horizontally written document with a page header
fantasai@7450 972 at the top of the page could use the
fantasai@7450 973 ''@bottom-left-corner'', ''@bottom-left'', ''@bottom-center'', ''@bottom-right'' and ''@bottom-right-corner''
fantasai@7450 974 page-margin boxes as the page footer.
fantasai@7450 975 The design of a vertically written document could use
fantasai@7450 976 the page-margin boxes of the binding edge of the page for the page footer.
fantasai@7450 977 </div>
fantasai@566 978
fantasai@7450 979 <p>Page-margin boxes are positioned with respect to the page area
fantasai@7450 980 and are independent of page orientation,
fantasai@7450 981 for example the top page-margin boxes are above the page area
fantasai@7450 982 in both portrait and landscape orientation.
fantasai@7450 983 The various page-margin boxes are defined
fantasai@7450 984 and illustrated in the diagram below:
fantasai@566 985
simon@7289 986 <table id="margin-box-def" class="data" summary="defintion of each of the page-margin boxes">
simon@7289 987 <caption>Table 1 Page-Margin Box Definitions</caption>
fantasai@566 988 <thead>
fantasai@566 989 <tr>
fantasai@566 990 <th>Box</th>
fantasai@566 991 <th>Description</th>
fantasai@566 992 <th>Placement</th>
fantasai@566 993 </tr>
fantasai@566 994 </thead>
fantasai@566 995 <tbody>
fantasai@566 996 <tr id="top-margin-boxes-def">
fantasai@566 997 <th id="top-left-corner-box-def">top-left-corner</th>
fantasai@566 998 <td>a fixed-size box defined by the intersection of the top and left margins of the
fantasai@566 999 page box</td>
fantasai@566 1000 <td><img src="TopLeftCornerBox.png" alt="the top left corner box with margin, border, and padding, nested within intersection of the page's top and left margins"
fantasai@566 1001 height="47" width="181"></td>
fantasai@566 1002 </tr>
fantasai@566 1003 <tr id="top-left-box-def">
fantasai@566 1004 <th>top-left</th>
fantasai@566 1005 <td>a variable-width box filling the top page margin between the top-left-corner
simon@7289 1006 and top-center page-margin boxes</td>
fantasai@566 1007 <td><img src="TopLeftMarginBox.png" alt="the top left box with margin, border, and padding, nested in the page's top margin next to the top left corner box"
fantasai@566 1008 height="47" width="181"></td>
fantasai@566 1009 </tr>
fantasai@566 1010 <tr id="top-center-box-def">
fantasai@566 1011 <th>top-center</th>
fantasai@566 1012 <td>a variable-width box centered horizontally between the page's left and right
fantasai@566 1013 border edges and filling the page top margin between the top-left and top-right
simon@7289 1014 page-margin boxes</td>
fantasai@566 1015 <td><img src="TopCenterMarginBox.png" alt="the top center box with margin, border, and padding, centered within the page's top margin"
fantasai@566 1016 height="47" width="181"></td>
fantasai@566 1017 </tr>
fantasai@566 1018 <tr id="top-right-box-def">
fantasai@566 1019 <th>top-right</th>
fantasai@566 1020 <td>a variable-width box filling the top page margin between the top-center and
simon@7289 1021 top-right-corner page-margin boxes</td>
fantasai@566 1022 <td><img src="TopRightMarginBox.png" alt="the top right box with margin, border, and padding, nested within the page's top margin"
fantasai@566 1023 height="47" width="181"></td>
fantasai@566 1024 </tr>
fantasai@566 1025 <tr>
fantasai@566 1026 <th id="top-right-corner-box-def">top-right-corner</th>
fantasai@566 1027 <td>a fixed-size box defined by the intersection of the top and right margins of
fantasai@566 1028 the page box</td>
fantasai@566 1029 <td><img src="TopRightCornerMarginBox.png" alt="the top right corner box with margin, border, and padding, nested within the intersection of the page's top and right margin"
fantasai@566 1030 height="47" width="181"></td>
fantasai@566 1031 </tr>
fantasai@566 1032 <tr id="left-margin-boxes-def">
fantasai@566 1033 <th id="left-top-box-def">left-top</th>
fantasai@566 1034 <td>a variable-height box filling the left page margin between the top-left-corner
simon@7289 1035 and left-middle page-margin boxes</td>
simon@7289 1036 <td rowspan="3"><img src="LeftMarginBoxes.png" alt="left-top, left-middle, and left-bottom page-margin boxes in the page box's left margin"
fantasai@566 1037 height="226" width="181"></td>
fantasai@566 1038 </tr>
fantasai@566 1039 <tr id="left-middle-box-def">
fantasai@566 1040 <th>left-middle</th>
fantasai@566 1041 <td>a variable-height box centered vertically between the page's top and bottom
fantasai@566 1042 border edges and filling the left page margin between the left-top and
simon@7289 1043 left-bottom page-margin boxes</td>
fantasai@566 1044 </tr>
fantasai@566 1045 <tr id="left-bottom-box-def">
fantasai@566 1046 <th>left-bottom</th>
fantasai@566 1047 <td>a variable-height box filling the left page margin between the left-middle and
simon@7289 1048 bottom-left-corner page-margin boxes</td>
fantasai@566 1049 </tr>
fantasai@566 1050 <tr id="right-margin-boxes-def">
fantasai@566 1051 <th id="right-top-box-def">right-top</th>
fantasai@566 1052 <td>a variable-height box filling the right page margin between the
simon@7289 1053 top-right-corner and right-middle page-margin boxes</td>
simon@7289 1054 <td rowspan="3"><img src="RightMarginBoxes.png" alt="right-top, right-middle, and right-bottom page-margin boxes in the page box's right margin"
fantasai@566 1055 height="226" width="181"></td>
fantasai@566 1056 </tr>
fantasai@566 1057 <tr id="right-middle-box-def">
fantasai@566 1058 <th>right-middle</th>
fantasai@566 1059 <td>a variable-height box centered vertically between the page's top and bottom
fantasai@566 1060 border edges and filling the right page margin between the right-top and
simon@7289 1061 right-bottom page-margin boxes</td>
fantasai@566 1062 </tr>
fantasai@566 1063 <tr id="right-bottom-box-def">
fantasai@566 1064 <th>right-bottom</th>
fantasai@566 1065 <td>a variable-height box filling the right page margin between the right-middle
simon@7289 1066 and bottom-right-corner page-margin boxes</td>
fantasai@566 1067 </tr>
fantasai@566 1068 <tr id="bottom-margin-boxes-def">
fantasai@566 1069 <th id="bottom-left-corner-box-def">bottom-left-corner</th>
fantasai@566 1070 <td>a fixed-size box defined by the intersection of the bottom and left margins of
fantasai@566 1071 the page box</td>
fantasai@566 1072 <td><img src="BottomLeftCornerBox.png" alt="bottom left corner box with margin, border, and padding, nested within the page margin at the intersection of the left and bottom page margins"
fantasai@566 1073 height="48" width="181"></td>
fantasai@566 1074 </tr>
fantasai@566 1075 <tr id="bottom-left-box-def">
fantasai@566 1076 <th>bottom-left</th>
fantasai@566 1077 <td>a variable-width box filling the bottom page margin between the
simon@7289 1078 bottom-left-corner and bottom-center page-margin boxes</td>
simon@7289 1079 <td><img src="BottomLeftMarginBox.png" alt="bottom left page-margin box with margin, border, and padding, nested within the page's bottom margin next to the bottom-left-corner box"
fantasai@566 1080 height="48" width="181"></td>
fantasai@566 1081 </tr>
fantasai@566 1082 <tr id="bottom-center-box-def">
fantasai@566 1083 <th>bottom-center</th>
fantasai@566 1084 <td>a variable-width box centered horizontally between the page's left and right
fantasai@566 1085 border edges and filling the bottom page margin between the bottom-left and
simon@7289 1086 bottom-right page-margin boxes</td>
fantasai@566 1087 <td style="vertical-align: middle;"><img src="BottomCenterMarginBox.png" alt="bottom center box with margin, border, and padding, nested within the page's bottom margin and centered on the page"
fantasai@566 1088 height="48" width="181"></td>
fantasai@566 1089 </tr>
fantasai@566 1090 <tr id="bottom-right-box-def">
fantasai@566 1091 <th>bottom-right</th>
fantasai@566 1092 <td>a variable-width box filling the bottom page margin between the bottom-center
simon@7289 1093 and bottom-right-corner page-margin boxes</td>
simon@7289 1094 <td><img src="BottomRightMarginBox.png" alt="bottom right page-margin box with margin, border, and padding, nested within the page's bottom margin and next to the bottom-right-corner box"
fantasai@566 1095 height="48" width="181"></td>
fantasai@566 1096 </tr>
fantasai@566 1097 <tr id="bottom-right-corner-box-def">
fantasai@566 1098 <th>bottom-right-corner</th>
fantasai@566 1099 <td>a fixed-size box defined by the intersection of the bottom and right margins of
fantasai@566 1100 the page box</td>
fantasai@566 1101 <td><img src="BottomRightCornerBox.png" alt="bottom right corner box with margin, border, and padding, nested within the page margin at the intersection of the right and bottom page margins"
fantasai@566 1102 height="48" width="181"></td>
fantasai@566 1103 </tr>
fantasai@566 1104 </tbody>
fantasai@566 1105 </table>
fantasai@566 1106
simon@7289 1107 <h3 id="margin-at-rules">At-rules for page-margin boxes</h3>
fantasai@566 1108
simon@7289 1109 <p>Page-margin boxes are created by
simon@7289 1110 <a href="#margin-at-rules">margin at-rules</a>
fantasai@1738 1111 inside the <a href="#page-context">page context</a>.
simon@7608 1112 Authors should put these rules after any declarations in the page context
simon@7608 1113 as legacy clients may not handle declarations
simon@7608 1114 after margin at-rules correctly.
simon@7608 1115 </p>
fantasai@566 1116
simon@7289 1117 <p>A <dfn id="margin-at-rule">margin at-rule</dfn> consists of an
simon@7289 1118 <a href="#specializatons-of-ATKEYWORD">ATKEYWORD</a>
simon@7289 1119 that identifies the page-margin box
fantasai@566 1120 (e.g. <span class="css">'@top-left'</span>) and a block of declarations (said
fantasai@566 1121 to be in the <dfn id="margin-context">margin context</dfn>).</p>
fantasai@566 1122
fantasai@566 1123 <div class="example">
fantasai@566 1124
fantasai@566 1125 <p>The following style sheet establishes a page header containing the title
fantasai@566 1126 ("Hamlet") on the left side and the page number, preceded by "Page ", on the
fantasai@566 1127 right side:</p>
fantasai@528 1128 <pre>
fantasai@566 1129 @page {
fantasai@566 1130 size: 8.5in 11in;
fantasai@566 1131 margin: 10%;
fantasai@528 1132
fantasai@566 1133 @top-left {
fantasai@566 1134 content: "Hamlet";
fantasai@566 1135 }
fantasai@566 1136 @top-right {
fantasai@566 1137 content: "Page " counter(page);
fantasai@566 1138 }
fantasai@528 1139 }
fantasai@528 1140 </pre>
fantasai@528 1141 </div>
fantasai@528 1142
fantasai@528 1143
simon@7289 1144 <h3 id="populating-margin-boxes">Populating page-margin boxes</h3>
fantasai@566 1145
fantasai@5969 1146 <p>As with the '':before'' and '':after'' pseudo-elements,
simon@7672 1147 a specified 'content: normal' on a page-margin box computes to ''none''.
simon@7672 1148 A page-margin box is <dfn>generated</dfn>
simon@7672 1149 if and only if the computed value of its 'content' property is not 'none'.
simon@7672 1150 Otherwise, no box is generated, as for elements with ''display: none''.
simon@7672 1151
simon@7672 1152 <p class=note>
simon@7672 1153 The 'display' property does not apply to page-margin boxes.
fantasai@528 1154
fantasai@528 1155 <div class="example">
fantasai@566 1156 <p>The following style sheet creates a green box in each corner of the page
fantasai@566 1157 except the bottom-left corner.</p>
fantasai@528 1158 <pre>
fantasai@566 1159 @page {
fantasai@566 1160 @top-left-corner { content: " "; border: solid green; }
fantasai@1090 1161 @top-right-corner { content: url(foo.png); border: solid green; }
fantasai@1090 1162 @bottom-right-corner { content: counter(page); border: solid green; }
fantasai@566 1163 @bottom-left-corner { content: normal; border: solid green; }
fantasai@566 1164 }
fantasai@528 1165 </pre>
fantasai@528 1166 </div>
fantasai@528 1167
fantasai@7449 1168 <h3 id="margin-dimension">Computing Page-margin Box Dimensions</h3>
fantasai@566 1169
simon@7289 1170 <p>The width and height of each page-margin box is determined by the rules
fantasai@1090 1171 below. These rules define the equivalent of CSS2.1 Sections 10.3 and
simon@7289 1172 10.6 for page-margin boxes.</p>
fantasai@1090 1173
fantasai@1090 1174 <p>The rules for applying 'min-height', 'max-height', 'min-width', and
simon@7289 1175 'max-width' [[!CSS21]] do apply to page-margin boxes and may imply
simon@7289 1176 a recalculation of the width, height, and/or margins
simon@7289 1177 if the dimensions resulting from the specified 'width' or 'height'
simon@7289 1178 violate their constraints.
simon@7289 1179 If the UA does not support the 'min-height' or 'min-width' properties
simon@7289 1180 then it must behave as if 'min-height' and 'min-width' were always zero.
fantasai@566 1181
fantasai@7449 1182 <h4 id="margin-box-terms"><a id="max-margin-dimension"></a>Page-Margin Box Layout Terminology</h4>
fantasai@566 1183
fantasai@7448 1184 <p>In addition to the box model definitions in CSS2.1 [[!CSS21]],
fantasai@7448 1185 and the sizing terms in CSS Intrinsic Sizing [[!CSS3-SIZING]],
fantasai@7448 1186 the following terms are defined for use
fantasai@7448 1187 in the subsequent page-margin box calculations:
fantasai@566 1188
fantasai@7448 1189 <dl>
fantasai@566 1190
fantasai@7448 1191 <dt><dfn>available width</dfn></dt>
fantasai@7448 1192 <dd>The sum of the page’s
fantasai@7448 1193 left border width, left padding, <a href="#page-box">page area</a> width,
fantasai@7448 1194 right padding, and right border width.
fantasai@7448 1195 In other words, it is the distance between
fantasai@7448 1196 the <a href="#page-box">page box</a>’s left right border edges.
fantasai@7448 1197 This quantity is used when calculating dimensions
fantasai@7448 1198 of the top and bottom page-margin boxes.
fantasai@566 1199
fantasai@7448 1200 <dt><dfn>available height</dfn></dt>
fantasai@7448 1201 <dd>The sum of the page’s
fantasai@7448 1202 top border width, top padding, <a href="#page-box">page area</a> height,
fantasai@7448 1203 bottom padding, and bottom border width.
fantasai@7448 1204 In other words, it is the distance between
fantasai@7448 1205 the <a href="#page-box">page box</a>’s top bottom border edges.
fantasai@7448 1206 This quantity is used when calculating dimensions
fantasai@7448 1207 of the left and right page-margin boxes.
fantasai@566 1208
simon@7496 1209 <dt><dfn>outer width</dfn></dt>
simon@7496 1210 <dd>The width of the
simon@7496 1211 <a href="http://www.w3.org/TR/CSS21/box.html#outer-edge">outer edge</a>,
simon@7496 1212 as defined in [[!CSS21]].
simon@7496 1213
fantasai@7448 1214 <dt><dfn>outer min width</dfn></dt>
fantasai@7448 1215 <dd>Like the <i>outer width</i>, except that
fantasai@7448 1216 <a href="http://www.w3.org/TR/css3-sizing/#min-content">''min-content''</a>
fantasai@7448 1217 is used when the width is ''auto''.
simon@7455 1218
fantasai@7448 1219 <dt><dfn>outer max width</dfn></dt>
fantasai@7448 1220 <dd>Like the <i>outer width</i>, except that
fantasai@7448 1221 <a href="http://www.w3.org/TR/css3-sizing/#max-content">''max-content''</a>
fantasai@7448 1222 is used when 'width' is ''auto''.
fantasai@7448 1223 </dl>
simon@7455 1224
fantasai@7448 1225 <p>The <dfn>containing block</dfn> for a corner page-margin box is
fantasai@7448 1226 the rectangle defined by the intersection of the two page margins meeting at that corner.
simon@7455 1227
fantasai@7448 1228 <p>For all other page-margin boxes,
fantasai@7448 1229 the <dfn>containing block</dfn> is the rectangle
fantasai@7448 1230 formed by the encapsulating page margin minus the containing blocks of the
fantasai@7448 1231 adjacent corners' page-margin boxes.
fantasai@7448 1232 This means that the size of this containing block is given
fantasai@7448 1233 in one dimension by the used page margin and in the other dimension
fantasai@7448 1234 by the <i>available width</i>
fantasai@7448 1235 (for top and bottom page-margin boxes) or
fantasai@7448 1236 <i>available height</i>
fantasai@7448 1237 (for left and right page-margin boxes).</p>
fantasai@566 1238
fantasai@7449 1239 <h4 id="variable-sizing">
fantasai@7448 1240 Page-Margin Box Variable Dimension Computation Rules</h4>
fantasai@566 1241
simon@7289 1242 <p>The following rules apply to 'top-left', 'top-center' and 'top-right'
simon@7289 1243 page-margin boxes,
simon@7289 1244 which are referred to as A, B, and C, respectively, in this section.</p>
simon@6957 1245
fantasai@7449 1246 <h5 id="variable-auto-margins">Margins</h5>
simon@7053 1247
simon@6957 1248 <p>If the 'margin-left' or 'margin-right' property of any of the three boxes
simon@6957 1249 computes to ''auto'', the used value is zero.</p>
simon@6957 1250
fantasai@7449 1251 <h5 id="variable-auto-sizing">Resolving ''auto'' widths</h5>
fantasai@566 1252
simon@6957 1253 <p>The following algorithm determines the used width of each box.
simon@7055 1254 For this purpose, boxes that are not <i>generated</i>
simon@7052 1255 are assumed to have a 'width' and an <i>outer width</i> of zero.
simon@7052 1256 </p>
simon@6957 1257
simon@6957 1258 <p class="note">
simon@6958 1259 Note: The high-level goals are (in order of priority) to center the middle
simon@6957 1260 box (B) if it is generated, to minimize overflow and overlap, and to
simon@6957 1261 distribute space proportionally to the amount of content.</p>
simon@6957 1262
fantasai@7448 1263 <p>If the middle box (B) is not <i>generated</i>,
fantasai@7448 1264 distribute the <i>available width</i> to A and C as follows:
simon@6957 1265
fantasai@7448 1266 <ul>
fantasai@7448 1267 <li>
fantasai@7448 1268 If only one box has 'width: auto',
fantasai@7448 1269 its used width is resolved so that
fantasai@7448 1270 the sum of the <i>outer width</i>s equals <i>available width</i>.
fantasai@7448 1271 </li>
simon@6957 1272
fantasai@7448 1273 <li id="flex-fit">
fantasai@7448 1274 If A and C both have 'width: auto', distribute the space to each box as follows:
fantasai@7448 1275 <ol>
fantasai@7448 1276 <li>If the sum of the outer <i>max-content widths</i> is less than the <i>available width</i>,
fantasai@7448 1277 call that difference the <i>flex space</i>.
fantasai@7448 1278 Calculate each box's <i>flex factor</i> as proportional to
fantasai@7448 1279 its outer <i>max-content width</i>,
fantasai@7448 1280 and set its used outer width to:
fantasai@7448 1281 <pre><i>max-content width</i> + <i>flex space</i> × <i>flex factor</i> ÷ ∑<i>flex factors</i></pre>
fantasai@7448 1282 <li>Otherwise if the sum of the outer <i>min-content widths</i> is less than the <i>available width</i>,
fantasai@7448 1283 call that difference the <i>flex space</i>
fantasai@7448 1284 calculate each box's <i>flex factor</i> as proportional to
fantasai@7448 1285 its <i>max-content</i> minus <i>min-content</i>,
fantasai@7448 1286 and set its used outer width to:
fantasai@7448 1287 <pre><i>min-content width</i> + <i>flex space</i> × <i>flex factor</i> ÷ ∑<i>flex factors</i></pre>
fantasai@7448 1288 <li>Otherwise,
fantasai@7448 1289 calculate its outer size as in the previous case,
fantasai@7448 1290 but set each box's <i>flex factor</i> as proportional to
fantasai@7448 1291 its outer <i>min-content width</i>.
fantasai@7448 1292 </ol>
fantasai@7448 1293 In each case, both <i>flex factors</i> are assumed to be ''1'' if their sum is equal to zero.
fantasai@7448 1294 </li>
fantasai@7448 1295 </ul>
simon@7455 1296
fantasai@7448 1297 <p>If the middle box (B) is <i>generated</i>,
fantasai@7448 1298 determine the ''auto'' widths of A, B, and C as follows:
simon@6957 1299
fantasai@7448 1300 <ol>
fantasai@7448 1301 <li>
fantasai@7448 1302 First, resolve any ''auto'' width of the middle box (B):
fantasai@7448 1303 Assume there are two boxes, B and AC,
fantasai@7448 1304 where each of AC's dimensions is double the maximum of A and C.
fantasai@7448 1305 (This preserves B's centering.)
fantasai@7448 1306 Distribute the space to these two boxes (B and the imaginary AC)
fantasai@7448 1307 as described for A and C <a href="#fit2">above</a>.
fantasai@7448 1308 <li>
fantasai@7448 1309 Then, resolve any ''auto'' widths of the side boxes (A and C)
fantasai@7448 1310 by setting that box's outer width to
fantasai@7448 1311 <pre>(<i>available width</i> &minus; <i>used outer size of B</i>) ÷ 2<pre>
fantasai@7448 1312 </li>
fantasai@7448 1313 </ol>
simon@6957 1314
fantasai@7449 1315 <h5 id="variable-minmax">Handling 'min-width' and 'max-width'</h5>
simon@7054 1316
simon@7054 1317 <p>
simon@7054 1318 The 'min-width' and 'max-width' properties [[CSS21]] apply to page-margin
simon@7054 1319 boxes in the variable dimension like on normal elements, except that the
simon@7054 1320 three boxes on the same side are considered together.
simon@7054 1321 </p>
simon@7054 1322
simon@7054 1323 <p>
simon@7054 1324 More precisely:
simon@7054 1325 </p>
simon@7054 1326
simon@7054 1327 <ol>
simon@7054 1328 <li>
simon@7054 1329 The tentative used widths are calculated
simon@7054 1330 (without 'min-width' and 'max-width') following the rules under
simon@7054 1331 <a href="#marginbox-variabledim-with">Resolving ''auto'' widths</a>
simon@7054 1332 above.
simon@7054 1333 </li>
simon@7054 1334 <li>
simon@7054 1335 If the tentative used width of any of the three boxes
simon@7054 1336 is greater than 'max-width', the rules above are applied again,
simon@7054 1337 but this time using the computed value of 'max-width'
simon@7054 1338 as the computed value for 'width'.
simon@7054 1339 </li>
simon@7054 1340 <li>
simon@7054 1341 If the resulting width of any of the three boxes
simon@7054 1342 is smaller than 'min-width', the rules above are applied again,
simon@7054 1343 but this time using the value of 'min-width'
simon@7054 1344 as the computed value for 'width'.
simon@7054 1345 </li>
simon@7054 1346 </ol>
simon@7054 1347
fantasai@7449 1348 <h5 id="variable-position">Positioning</h5>
simon@7053 1349
simon@7053 1350 <p>
simon@7053 1351 Once the dimensions of the boxes are determined,
simon@7053 1352 they are positioned as follows:
simon@7053 1353 </p>
simon@7053 1354
simon@7053 1355 <ul>
simon@7053 1356 <li>The left outer edge of A is flush with the left edge of the
simon@7053 1357 containing block</li>
simon@7053 1358 <li>The outer area of B is centered in the containing block.</li>
simon@7053 1359 <li>The right outer edge of C is flush with the right edge of the
simon@7053 1360 containing block.</li>
simon@7053 1361 </ul>
simon@7053 1362
fantasai@7449 1363 <h5 id="variable-mapping">Boxes on other sides</h5>
fantasai@566 1364
simon@7289 1365 <p>The used values for 'bottom-left', 'bottom-center' and 'bottom-right'
simon@7289 1366 page-margin boxes are established by the same rules as
simon@7289 1367 for 'top-left', 'top-center', and 'top-right', respectively.</p>
fantasai@566 1368
fantasai@566 1369 <p>The used values for 'left-top', 'left-middle' and 'left-bottom' boxes are
fantasai@566 1370 established by the same rules, with "width" replaced by "height", "left" by
fantasai@566 1371 "top", "right" by "bottom" and "center" by "middle".</p>
fantasai@566 1372
simon@7289 1373 <p>The used values for 'right-top', 'right-middle' and 'right-bottom'
simon@7289 1374 page-margin boxes
fantasai@566 1375 are established by the same rules as for 'left-top', 'left-middle' and
fantasai@566 1376 'left-bottom', respectively.</p>
fantasai@566 1377
fantasai@7449 1378 <h4 id="fixed-sizing">Page-Margin Box Fixed Dimension Computation Rules</h4>
fantasai@566 1379
fantasai@1090 1380 <p>The rules below are used to calculate the used values of each
fantasai@566 1381 'top-left-corner', 'top-left', 'top-center', 'top-right', and
simon@7289 1382 'top-right-corner' page-margin box's 'height', 'margin-top', and 'margin-bottom'
fantasai@1090 1383 properties:</p>
fantasai@566 1384
fantasai@1090 1385 <ol>
fantasai@1090 1386 <li>The following constraint must hold among the used values of the margin
fantasai@1090 1387 box's properties:
fantasai@1090 1388 <p>'margin-top' + 'border-top-width' + 'padding-top' + 'height' +
fantasai@1090 1389 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' = top page margin
fantasai@566 1390
fantasai@1090 1391 <li>If 'border-top-width' + 'padding-top' + 'height' (if it is not ''auto'')
fantasai@1090 1392 + 'padding-bottom' + 'border-bottom-width', plus 'margin-top' and/or
fantasai@1090 1393 'margin-bottom' if not ''auto'', is larger than the height of the top page
fantasai@1090 1394 margin, then any ''auto'' values for 'margin-top' or 'margin-bottom' are, for
fantasai@1090 1395 the following rules, treated as zero.
fantasai@566 1396
fantasai@1090 1397 <li>If at this point all of 'height', 'margin-top', and 'margin-bottom'
fantasai@1090 1398 have a computed value other than ''auto'', the values are said to be
fantasai@1090 1399 "over-constrained". In this case, the specified value of 'margin-top' is
fantasai@1090 1400 treated as 'auto'.
fantasai@566 1401
fantasai@1090 1402 <li>If there is now exactly one value specified as 'auto', its used value
fantasai@1090 1403 follows from the equality.
fantasai@566 1404
fantasai@1090 1405 <li>If 'height' is set to 'auto', any other 'auto' values become '0' and
fantasai@1090 1406 'height' follows from the resulting equality
fantasai@566 1407
simon@7289 1408 <li>If both 'margin-top' and 'margin-bottom' are 'auto',
simon@7289 1409 their used values are equal.
simon@7289 1410 This vertically centers the page-margin box content
simon@7289 1411 within the top page margin.
fantasai@1090 1412 </ol>
fantasai@566 1413
simon@7289 1414 <p>The same rules apply to the bottom page-margin boxes (bottom-left-corner,
fantasai@566 1415 bottom-left, bottom-center, bottom-right, and bottom-right-corner), except that
fantasai@566 1416 in the overconstrained case, the 'margin-bottom' is ignored rather than the
fantasai@566 1417 'margin-top'.</p>
fantasai@566 1418
simon@7289 1419 <p>Analogous rules govern the properties for the left and right
simon@7289 1420 page-margin boxes with respect to 'width'
simon@7289 1421 (top-left-corner, left-top, left-middle, left-bottom, and
fantasai@566 1422 bottom-left-corner; top-right-corner, right-top, right-middle, right-bottom,
fantasai@566 1423 bottom-right-corner), with 'top' replaced by 'left', 'bottom' replaced by
simon@7289 1424 'right', and 'height' replaced by 'width'.
simon@7289 1425 In the overconstrained case for left (right) page-margin boxes,
simon@7289 1426 the specified value of 'margin-left' ('margin-right') is ignored.</p>
fantasai@566 1427
simon@7289 1428 <h3 id="margin-box-ex">Page-margin box examples</h3>
fantasai@566 1429
simon@7289 1430 <p>The following is a collection of examples of page-margin box usage.</p>
fantasai@566 1431
fantasai@528 1432 <div class="example">
fantasai@566 1433
fantasai@566 1434 <p>Here is an example of a page with only a top-left header:</p>
fantasai@528 1435 <pre>
fantasai@566 1436 @page {
fantasai@566 1437 @top-left { content: "Header in Left Cell (top-left)" }
fantasai@566 1438 }
fantasai@528 1439 </pre>
fantasai@528 1440
fantasai@566 1441 <p>Because there are no contents defined for the top-center or the top-right
simon@7289 1442 page-margin boxes, the extent of the top-left page-margin box
simon@7289 1443 is allowed to cross the center of the page box.</p>
fantasai@566 1444
fantasai@566 1445 <p><img alt="Header Example 1" src="header-ex-1.png" height="177" width="737"></p>
fantasai@528 1446 </div>
fantasai@528 1447
fantasai@566 1448 <div class="example">
fantasai@566 1449
fantasai@566 1450 <p>The following is an example of a page with a centered header:</p>
fantasai@566 1451 <pre>
fantasai@566 1452 @page {
fantasai@566 1453 @top-center { content: "Header in Center Cell (top-center)" }
fantasai@566 1454 }
fantasai@566 1455 </pre>
fantasai@566 1456
fantasai@566 1457 <p><img alt="Header Example 2" src="header-ex-2.png" height="177" width="737"></p>
fantasai@528 1458 </div>
fantasai@528 1459
fantasai@566 1460 <div class="example">
fantasai@566 1461
fantasai@566 1462 <p>The following is an example of a page with a single header in the top-right
simon@7289 1463 page-margin box:</p>
fantasai@566 1464 <pre>
fantasai@566 1465 @page {
fantasai@566 1466 @top-right { content: "Header in Right Cell (top-right)" }
fantasai@566 1467 }
fantasai@566 1468 </pre>
fantasai@566 1469
fantasai@566 1470 <p>Because the content of the center cell is empty, the extent of the top-right
simon@7289 1471 page-margin box is allowed to cross the center of the page box.</p>
fantasai@566 1472
fantasai@566 1473 <p><img alt="Header Example 3" src="header-ex-3.png" height="177" width="737"></p>
fantasai@566 1474 </div>
fantasai@566 1475
fantasai@566 1476 <div class="example">
fantasai@566 1477
fantasai@566 1478 <p>The following is an example of a page with a top-center and a top-left header:</p>
fantasai@566 1479 <pre>
fantasai@566 1480 @page {
fantasai@566 1481 @top-left { content: "Left Cell (top-left)" }
fantasai@566 1482 @top-center { content: "Header in Center Cell (top-center)" }
fantasai@566 1483 }
fantasai@566 1484 </pre>
fantasai@566 1485
fantasai@566 1486 <p><img alt="Header Example 4" src="header-ex-4.png" height="177" width="737"></p>
fantasai@566 1487 </div>
fantasai@566 1488
fantasai@566 1489 <div class="example">
fantasai@566 1490
fantasai@566 1491 <p>The following is an example of a page with a top-center and a top-right header:</p>
fantasai@566 1492 <pre>
fantasai@566 1493 @page {
fantasai@566 1494 @top-center { content: "Header in Center Cell (top-center)" }
fantasai@566 1495 @top-right { content: "Right Cell (top-right)" }
fantasai@566 1496 }
fantasai@566 1497 </pre>
fantasai@566 1498
fantasai@566 1499 <p><img alt="Header Example 5" src="header-ex-5.png" height="177" width="737"></p>
fantasai@566 1500 </div>
fantasai@566 1501
fantasai@566 1502 <div class="example">
fantasai@566 1503
fantasai@566 1504 <p>The following is an example of a page with top-left and top-right headers:</p>
fantasai@566 1505 <pre>
fantasai@566 1506 @page {
fantasai@566 1507 @top-left { content: "Header in top-left with approx. "
fantasai@566 1508 "twice as many words as right cell." }
fantasai@566 1509 @top-right { content: "Right cell (top-right)" }
fantasai@566 1510 }
fantasai@566 1511 </pre>
fantasai@566 1512
fantasai@566 1513 <p>Because there are no center cell contents, the extent of the top-left is
fantasai@5974 1514 allowed to cross the center of the page box.</p>
fantasai@566 1515
fantasai@566 1516 <p><img alt="Header Example 6" src="header-ex-6.png" height="177" width="737"></p>
fantasai@528 1517 </div>
fantasai@528 1518
fantasai@528 1519 <h2 id="page-properties">Page Properties</h2>
fantasai@528 1520 <div>
fantasai@528 1521
simon@7573 1522 <p>
simon@7573 1523 <a href="#properties-list">Appendix A</a> defines the normative list of
simon@7573 1524 CSS 2.1 [[!CSS21]]
simon@7573 1525 <a href="#page-property-list">properties that apply to page boxes</a>.
simon@7573 1526 If a conforming user agent supports any of these properties on block boxes,
simon@7573 1527 then it <em class="RFC2119">MUST</em> also support that property
simon@7573 1528 in the <i>page context</i>.
simon@7573 1529 This specification additionally defines the 'size' property
simon@7573 1530 that only applies in the page context.
fantasai@528 1531
simon@7573 1532 <p>
simon@7573 1533 Properties that apply to the page-margin boxes can also be set
simon@7573 1534 within the page context:
simon@7573 1535 if inheritable or explicitly inherited
simon@7573 1536 (with the ''inherit'' keyword in the margin context),
simon@7573 1537 they will inherit to the page-margin boxes.
fantasai@528 1538
simon@7573 1539 <p>
simon@7573 1540 The same appendix defines the normative list of
simon@7573 1541 CSS 2.1 [[!CSS21]]
simon@7573 1542 <a href="#page-property-list">properties that apply to page-margin boxes</a>.
simon@7573 1543 If a conforming user agent supports any of these properties on block boxes,
simon@7573 1544 then it <em class="RFC2119">MUST</em> also support that property
simon@7676 1545 in the <i>margin context</i>.
fantasai@528 1546
simon@7573 1547 <p>
simon@7573 1548 Other properties defined by [[!CSS21]] do not apply in these contexts.
simon@7573 1549 Behavior for properties not included in CSS 2.1 is undefined.
fantasai@3574 1550
fantasai@528 1551 <p class="note">
fantasai@528 1552 Note: The intent of leaving other properties undefined is to allow the gradual
fantasai@528 1553 addition of appropriate CSS3 properties as they emerge, without having to
fantasai@528 1554 update this specification with each addition.</p>
fantasai@528 1555
fantasai@1133 1556 <p><a href="http://www.w3.org/TR/CSS21/cascade.html#value-stages">As with
fantasai@1133 1557 elements in the document</a>, both the page context and the margin context
fantasai@1133 1558 have a computed value for every property, even if that property does not
simon@7289 1559 apply to the page or page-margin box.</p>
fantasai@1133 1560
fantasai@566 1561 <p>The normal rules for CSS properties apply with the following exceptions:</p>
fantasai@528 1562
fantasai@528 1563 <ul>
simon@7289 1564 <li>page-margin boxes inherit from the page context.
simon@7289 1565 The page context inherits from the root element.
simon@7289 1566 However, since the previous revision of CSS Paged
fantasai@1090 1567 Media Level 3 did not specify this point, an implementation that sets
fantasai@1090 1568 inherited properties in the page context to their initial values (as for the
fantasai@1090 1569 root element) is also conformant to CSS Paged Media Level 3. Note that this
fantasai@1090 1570 exception will be removed in Level 4.
fantasai@1090 1571 <li>Values in units of ''em'' and ''ex'' are interpreted relative to the font
fantasai@1090 1572 associated with their context. When used on the 'font-size' property in the
fantasai@1090 1573 margin context, they are relative to the font of the page context. When used
fantasai@1090 1574 on the 'font-size' property in the page context, they are relative to the
fantasai@1090 1575 'font-size' of the root element. However, since a previous revision of CSS
fantasai@1090 1576 Paged Media Level 3 was ambiguous on this point, an implementation that
fantasai@1090 1577 treats ''em'' and ''ex'' on 'font-size' as relative to the initial value is
fantasai@1090 1578 also conformant to CSS Paged Media Level 3. Note that this exception will
fantasai@1090 1579 be removed in Level 4.
fantasai@528 1580 <li>Percentage values on the margin and padding properties are relative to the
fantasai@528 1581 dimensions of the containing block. For right and left values, percentages are
fantasai@528 1582 relative to the width of the containing block; for top and bottom values,
fantasai@528 1583 percentages are relative to the height of the containing block.</li>
fantasai@3574 1584 <li>The used values of 'width' and 'height' have special computation rules
simon@7289 1585 for page boxes and page-margin boxes; see <a href="#page-size">Page Size</a>
simon@7289 1586 and <a href="#margin-box-dimensions">Computing Page-Margin Box Dimensions</a>.
fantasai@6061 1587 <li>The page background is positioned and painted
fantasai@6061 1588 <a href="#painting">as described above</a>.
fantasai@566 1589 <li>The rules for counter scoping are modified <a href="page-based-counters">as
fantasai@566 1590 described below</a>.</li>
simon@7433 1591 <li>
simon@7433 1592 As on the '::before' and '::after' pseudo-elements,
simon@7433 1593 the ''normal'' value of the 'content' property computes to ''none''
simon@7433 1594 on page-margin boxes.
simon@7433 1595 </li>
simon@7289 1596 <li>On page-margin boxes, the 'vertical-align' property behaves
fantasai@5975 1597 <a href="http://www.w3.org/TR/CSS21/tables.html#height-layout">as specified for table cells</a>.
fantasai@5975 1598 It <em>always</em> performs alignment in the vertical dimension,
fantasai@5975 1599 regardless of writing mode.
fantasai@528 1600 </ul>
fantasai@528 1601
fantasai@528 1602 <p>It is <em class="RFC2119">recommended</em> that user agents establish a default
fantasai@528 1603 page margin via the user agent stylesheet that includes any non-printable area.
fantasai@528 1604 It is further <em class="RFC2119">recommended</em> that authors assume that the
fantasai@528 1605 default page area will not include unprintable regions.</p>
fantasai@528 1606
fantasai@566 1607 <h3 id="page-based-counters">Page-based counters</h3>
fantasai@566 1608
fantasai@566 1609 <p>Counters can be defined and controlled within an <span class="css">'@page'</span>
simon@7289 1610 rule, and used as content in page-margin boxes.
simon@7289 1611 This is useful for maintaining a page count.</p>
fantasai@566 1612
fantasai@566 1613 <p>A 'counter-increment' within either a page or margin context causes the counter
fantasai@566 1614 to increment with the generation of each page box.</p>
fantasai@566 1615
fantasai@566 1616 <p>If a counter is reset or incremented within the page context, it is in scope
simon@7289 1617 for all page-margin boxes and obscures all counters of the same name within the
fantasai@566 1618 document.</p>
fantasai@566 1619
fantasai@566 1620 <p>If a counter is reset or incremented within a margin context, it is in scope
simon@7289 1621 for that page-margin box and obscures any counters of the same name
simon@7289 1622 in both the page context and the document.</p>
fantasai@566 1623
fantasai@566 1624 <p>If a counter that has not been reset or incremented within the margin context
fantasai@566 1625 or the page context is used by counter() or counters() in the margin context,
simon@7289 1626 then the resultant value is exactly
simon@7289 1627 as if the page-margin box were an element within
fantasai@566 1628 the document at the start of the page, inside the deepest element in the normal
fantasai@566 1629 flow that spans the page break. Use of the counter in this way does not affect
fantasai@566 1630 the calculation of the counter's value.</p>
fantasai@566 1631
simon@7441 1632 <p>
simon@7441 1633 A counter named ''page'' is automatically created
simon@7441 1634 and incremented by 1 on every page of the document,
simon@7441 1635 unless the 'counter-increment' property in the <i>page context</i>
simon@7441 1636 explicitly specifies a different increment for the ''page'' counter.
simon@7441 1637 The implied ''page'' counter is a real counter,
simon@7441 1638 and can be directly affected using the 'counter-increment' and 'counter-reset' properties
simon@7441 1639 when named explicitly in those properties.
simon@7441 1640 It can also be used in the 'counter()' and 'counters()' function forms.
simon@7441 1641 </p>
simon@7441 1642
simon@7441 1643 <div class="example">
simon@7441 1644 <p>The following rules result in the placement of the current page number in the
simon@7441 1645 middle of the outside margin of each page.</p>
simon@7441 1646 <pre>
simon@7441 1647 @page {
simon@7441 1648 margin: 10%;
simon@7441 1649
simon@7441 1650 @top-center {
simon@7441 1651 font-family: sans-serif;
simon@7441 1652 font-weight: bold;
simon@7441 1653 font-size: 2em;
simon@7441 1654 content: counter(page);
simon@7441 1655 }
simon@7441 1656 }
simon@7441 1657 </pre>
simon@7441 1658
simon@7441 1659 <p>Adding the following rule will make all pages even-numbered.</p>
simon@7441 1660 <pre>
simon@7441 1661 @page {
simon@7441 1662 counter-increment: page 2;
simon@7441 1663 }
simon@7441 1664 </pre>
simon@7441 1665 </div>
fantasai@566 1666
fantasai@1101 1667 <p>Additionally, a counter named ''pages'' is automatically created by the UA.
fantasai@1101 1668 Its value is always the total number of pages in the document. (In continuous
fantasai@1101 1669 media this is always 1.) The value of ''pages'' cannot be manipulated: while
fantasai@1101 1670 'counter-reset' and 'counter-increment' statements that set it are valid, they
fantasai@1101 1671 have no effect.
fantasai@1101 1672
fantasai@566 1673 <p>In all other respects, page-associated counters behave as described in
fantasai@566 1674 [[!CSS21]], <a href="TR/CSS21/generate.html#scope">Nested Counters and
fantasai@5976 1675 Scope</a> and <a href="http://www.w3.org/TR/CSS21/syndata.html#counter">Counters</a>.</p>
fantasai@566 1676
simon@7289 1677 <h3 id="margin-text-alignment">Page-margin boxes and default values</h3>
fantasai@566 1678
fantasai@566 1679 <p>Properties used within page or margin contexts take their initial values from
fantasai@566 1680 their respective property definitions; however, user agents must behave as
fantasai@566 1681 though the values in the following table were established by rules in the UA
fantasai@566 1682 default style sheet.</p>
simon@7289 1683 <table id="margin-values" class="data" summary="definition of page-margin box default properties">
simon@7289 1684 <caption>Table 2. Default values for Page-Margin Boxes</caption>
fantasai@566 1685 <thead>
fantasai@566 1686 <tr>
simon@7289 1687 <th>Page-margin box</th>
fantasai@566 1688 <th><span class="property">'text-align'</span></th>
fantasai@566 1689 <th><span class="property">'vertical-align'</span></th>
fantasai@566 1690 </tr>
fantasai@566 1691 </thead>
fantasai@566 1692 <tbody>
fantasai@566 1693 <tr>
fantasai@566 1694 <td><a href="#top-left-corner-box-def">top-left-corner</a></td>
fantasai@566 1695 <td>right</td>
fantasai@566 1696 <td>middle</td>
fantasai@566 1697 </tr>
fantasai@566 1698 <tr>
fantasai@566 1699 <td><a href="#top-left-box-def">top-left</a></td>
fantasai@566 1700 <td>left</td>
fantasai@566 1701 <td>middle</td>
fantasai@566 1702 </tr>
fantasai@566 1703 <tr>
fantasai@566 1704 <td><a href="#top-center-box-def">top-center</a></td>
fantasai@566 1705 <td>center</td>
fantasai@566 1706 <td>middle</td>
fantasai@566 1707 </tr>
fantasai@566 1708 <tr>
fantasai@566 1709 <td><a href="#top-right-box-def">top-right</a></td>
fantasai@566 1710 <td>right</td>
fantasai@566 1711 <td>middle</td>
fantasai@566 1712 </tr>
fantasai@566 1713 <tr>
fantasai@566 1714 <td><a href="#top-right-corner-box-def">top-right-corner</a></td>
fantasai@566 1715 <td>left</td>
fantasai@566 1716 <td>middle</td>
fantasai@566 1717 </tr>
fantasai@566 1718 <tr>
fantasai@566 1719 <td><a href="#left-top-box-def">left-top</a></td>
fantasai@566 1720 <td>center</td>
fantasai@566 1721 <td>top</td>
fantasai@566 1722 </tr>
fantasai@566 1723 <tr>
fantasai@566 1724 <td><a href="#left-middle-box-def">left-middle</a></td>
fantasai@566 1725 <td>center</td>
fantasai@566 1726 <td>middle</td>
fantasai@566 1727 </tr>
fantasai@566 1728 <tr>
fantasai@566 1729 <td><a href="#left-bottom-box-def">left-bottom</a></td>
fantasai@566 1730 <td>center</td>
fantasai@566 1731 <td>bottom</td>
fantasai@566 1732 </tr>
fantasai@566 1733 <tr>
fantasai@566 1734 <td><a href="#right-top-box-def">right-top</a></td>
fantasai@566 1735 <td>center</td>
fantasai@566 1736 <td>top</td>
fantasai@566 1737 </tr>
fantasai@566 1738 <tr>
fantasai@566 1739 <td><a href="#right-middle-box-def">right-middle</a></td>
fantasai@566 1740 <td>center</td>
fantasai@566 1741 <td>middle</td>
fantasai@566 1742 </tr>
fantasai@566 1743 <tr>
fantasai@566 1744 <td><a href="#right-bottom-box-def">right-bottom</a></td>
fantasai@566 1745 <td>center</td>
fantasai@566 1746 <td>bottom</td>
fantasai@566 1747 </tr>
fantasai@566 1748 <tr>
fantasai@566 1749 <td><a href="#bottom-left-corner-box-def">bottom-left-corner</a></td>
fantasai@566 1750 <td>right</td>
fantasai@566 1751 <td>middle</td>
fantasai@566 1752 </tr>
fantasai@566 1753 <tr>
fantasai@566 1754 <td><a href="#bottom-left-box-def">bottom-left</a></td>
fantasai@566 1755 <td>left</td>
fantasai@566 1756 <td>middle</td>
fantasai@566 1757 </tr>
fantasai@566 1758 <tr>
fantasai@566 1759 <td><a href="#bottom-center-box-def">bottom-center</a></td>
fantasai@566 1760 <td>center</td>
fantasai@566 1761 <td>middle</td>
fantasai@566 1762 </tr>
fantasai@566 1763 <tr>
fantasai@566 1764 <td><a href="#bottom-right-box-def">bottom-right</a></td>
fantasai@566 1765 <td>right</td>
fantasai@566 1766 <td>middle</td>
fantasai@566 1767 </tr>
fantasai@566 1768 <tr>
fantasai@566 1769 <td><a href="#bottom-right-corner-box-def">bottom-right-corner</a></td>
fantasai@566 1770 <td>left</td>
fantasai@566 1771 <td>middle</td>
fantasai@566 1772 </tr>
fantasai@566 1773 </tbody>
fantasai@566 1774 </table>
fantasai@566 1775
fantasai@566 1776 <div class="example">
fantasai@566 1777
fantasai@566 1778 <p>This example style sheet could be used to create a centered header with the
fantasai@566 1779 current chapter name:</p>
fantasai@566 1780 <pre>body {counter-reset: chapter;}
fantasai@566 1781 div.chapter {counter-increment: chapter;}
fantasai@566 1782 @page {
fantasai@566 1783 margin: 10%;
fantasai@566 1784 @top-center { content: "Chapter" counter(chapter) }
fantasai@566 1785 }
fantasai@566 1786 </pre>
fantasai@566 1787 </div>
fantasai@566 1788
fantasai@3574 1789 <h2 id="page-size">Page Size</h2>
fantasai@213 1790
fantasai@213 1791 <p>People around the world use many different paper sizes. It is a goal of this
fantasai@213 1792 specification that web content should be adaptable to a range of different
fantasai@213 1793 sizes without having to write a specific style sheet for each paper size.</p>
fantasai@213 1794
fantasai@213 1795 <p>However, in some situations it is important that a certain page size achieves a
fantasai@213 1796 certain style. One way to achieve this goal is to utilize the 'size' property,
fantasai@213 1797 which indicates that the document should preferentially be displayed on a
fantasai@213 1798 surface of a certain size; another method is to use Media Queries [[MEDIAQ]]
fantasai@213 1799 which allow different style sheets to be applied to different page sizes.</p>
fantasai@213 1800
fantasai@528 1801 <h3 id="page-size-prop">Page size: the 'size' property</h3>
fantasai@3574 1802
fantasai@213 1803 <table class="propdef" summary="definition of the size property">
fantasai@213 1804 <tr>
fantasai@213 1805 <th>Name:
fantasai@213 1806 <td><dfn id="size">size</dfn>
fantasai@213 1807 <tr>
fantasai@213 1808 <th>Value:
fantasai@1124 1809 <td>&lt;length&gt;{1,2} | auto | [ &lt;page-size&gt; || [ portrait | landscape] ]
fantasai@213 1810 <tr>
fantasai@213 1811 <th>Initial:
fantasai@213 1812 <td>auto
fantasai@213 1813 <tr>
fantasai@213 1814 <td><em>Applies to:</em>
fantasai@213 1815 <td>page context
fantasai@213 1816 <tr>
fantasai@213 1817 <th>Inherited:
fantasai@213 1818 <td>N/A
fantasai@213 1819 <tr>
fantasai@213 1820 <th>Percentages:
fantasai@213 1821 <td>N/A
fantasai@213 1822 <tr>
fantasai@213 1823 <th>Media:
fantasai@213 1824 <td>paged
fantasai@213 1825 <tr>
fantasai@213 1826 <td><em>Computed value:</em>
fantasai@213 1827 <td>specified value
fantasai@213 1828 </table>
fantasai@213 1829
fantasai@3574 1830 <p>This property specifies the target size and orientation of the
simon@7491 1831 <a href="#page-box">page box</a>’s containing block.
fantasai@5973 1832 In the general case, where one page box is rendered onto one <a href="#page-sheet">page sheet</a>,
fantasai@5973 1833 the 'size' property also indicates the size of the destination page sheet.
fantasai@213 1834
fantasai@5987 1835 <p>The size of a page box can either be "absolute" (fixed size) or "scalable"
fantasai@5987 1836 (i.e., fitting available sheet sizes).
fantasai@5987 1837 The first three values in the table below can be used to create scalable page
fantasai@5987 1838 boxes.
fantasai@5987 1839 Other values define a fixed-size page box, and thereby indicate the preferred
fantasai@213 1840 output media size. When possible, output should be rendered on the media size
fantasai@5987 1841 indicated.
fantasai@5987 1842 If the specified size is not available, the rules for
fantasai@5987 1843 <a href="#renderingpages">transposing a page box to a different size</a>
fantasai@5987 1844 apply.</p>
fantasai@217 1845
fantasai@4555 1846 <p>If a <code>size</code> property declaration is qualified by a ''width'',
fantasai@4568 1847 ''height'', ''device-width'', ''device-height'', ''aspect-ratio'',
fantasai@4568 1848 ''device-aspect-ratio'' or ''orientation''
fantasai@4568 1849 media query [[!MEDIAQ]] (or other conditional on the size of the paper), then
fantasai@4555 1850 the declaration must be
fantasai@4568 1851 <a href="http://www.w3.org/TR/CSS21/conform.html#ignore">ignored</a>. Media
fantasai@4568 1852 queries do not honor 'size': they assume the paper size that would be chosen
fantasai@4568 1853 if no @page rules were specified.</p>
fantasai@217 1854
fantasai@5987 1855 <p class=issue>It would be useful if media queries could respond at least
fantasai@5987 1856 to sizes specified on an unqualified @page.
fantasai@5987 1857
fantasai@217 1858 <div class="example">
fantasai@217 1859 <p>In the following example
fantasai@217 1860 <pre>
fantasai@217 1861 @page {
fantasai@217 1862 size: 4in 6in;
fantasai@217 1863 }
simon@6956 1864
fantasai@217 1865 @media (max-width: 6in) {
fantasai@217 1866 @page {
fantasai@217 1867 size: letter;
fantasai@217 1868 }
fantasai@217 1869 }
fantasai@217 1870 </pre>
fantasai@217 1871 <p>The second <code>size</code> declaration is ignored, i.e. the specified value
fantasai@217 1872 of the <code>size</code> property is <code>4in 6in</code>.
fantasai@217 1873 </div>
fantasai@217 1874
fantasai@213 1875 <table class="page-sizes">
fantasai@213 1876 <tr>
fantasai@213 1877 <th>Value</th>
fantasai@213 1878 <th>Description</th>
fantasai@213 1879 </tr>
fantasai@213 1880 <tr>
fantasai@213 1881 <td>auto</td>
fantasai@213 1882 <td>The page box will be set to a size and orientation chosen by the UA. In the
fantasai@213 1883 usual case, the page box size and orientation is chosen to match the target
fantasai@213 1884 media sheet.</td>
fantasai@213 1885 </tr>
fantasai@213 1886 <tr>
fantasai@213 1887 <td>landscape</td>
fantasai@213 1888 <td>Specifies that the page's content be printed in landscape orientation. The
fantasai@213 1889 longer sides of the page box are horizontal. If a <span class="css">'&lt;page-size&gt;'</span> is not specified, the size of the page sheet
fantasai@213 1890 is chosen by the UA.</td>
fantasai@213 1891 </tr>
fantasai@213 1892 <tr>
fantasai@213 1893 <td>portrait</td>
fantasai@213 1894 <td>Specifies that the page's content be printed in portrait orientation. The
fantasai@213 1895 shorter sides of the page box are horizontal. If a <span class="css">'&lt;page-size&gt;'</span> is not specified, the size of the page sheet
fantasai@213 1896 is chosen by the UA.</td>
fantasai@213 1897 </tr>
fantasai@213 1898 <tr>
fantasai@213 1899 <td>&lt;length&gt;</td>
fantasai@213 1900 <td>The page box will be set to the given absolute dimension(s). If only one length
fantasai@213 1901 value is specified, it sets both the width and height of the page box (i.e.,
fantasai@213 1902 the box is a square). If two length values are specified, the first establishes
fantasai@213 1903 the page box width, and the second the page box height. Values in units of
fantasai@213 1904 <span class="css">'em'</span> and <span class="css">'ex'</span> refer to the
fantasai@5988 1905 page context's font. Negative lengths are illegal.</td>
fantasai@213 1906 </tr>
fantasai@213 1907 <tr>
fantasai@213 1908 <td>&lt;page-size&gt;</td>
fantasai@213 1909 <td>A page size can be specified using one of the following media names. This is
fantasai@213 1910 the equivalent of specifying the <span class="css">'&lt;page-size&gt;'</span>
fantasai@213 1911 using length values. The definition of the the media names comes from
fantasai@213 1912 <cite>Media Standardized Names</cite> [[!PWGMSN]].
fantasai@213 1913
fantasai@213 1914 <dl>
fantasai@213 1915
fantasai@213 1916 <dt>A5</dt>
fantasai@213 1917 <dd>Equivalent to the size of ISO A5 media: 148mm wide and 210 mm high.</dd>
fantasai@213 1918
fantasai@213 1919 <dt>A4</dt>
simon@6795 1920 <dd>Equivalent to the size of ISO A4 media: 210 mm wide and 297 mm high.</dd>
fantasai@213 1921
fantasai@213 1922 <dt>A3</dt>
fantasai@213 1923 <dd>Equivalent to the size of ISO A3 media: 297mm wide and 420mm high.</dd>
fantasai@213 1924
fantasai@213 1925 <dt>B5</dt>
fantasai@213 1926 <dd>Equivalent to the size of ISO B5 media: 176mm wide by 250mm high.</dd>
fantasai@213 1927
fantasai@213 1928 <dt>B4</dt>
fantasai@213 1929 <dd>Equivalent to the size of ISO B4 media: 250mm wide by 353mm high.</dd>
fantasai@213 1930
fantasai@213 1931 <dt>letter</dt>
fantasai@213 1932 <dd>Equivalent to the size of North American letter media: 8.5 inches wide and 11
fantasai@213 1933 inches high</dd>
fantasai@213 1934
fantasai@213 1935 <dt>legal</dt>
fantasai@213 1936 <dd>Equivalent to the size of North American legal: 8.5 inches wide by 14 inches
fantasai@213 1937 high.</dd>
fantasai@213 1938
fantasai@213 1939 <dt>ledger</dt>
fantasai@213 1940 <dd>Equivalent to the size of North American ledger: 11 inches wide by 17 inches
fantasai@213 1941 high.</dd>
fantasai@213 1942 </dl></td>
fantasai@213 1943 </tr>
fantasai@213 1944 </table>
fantasai@213 1945
fantasai@213 1946 <p>The '&lt;page-size&gt;' names can be used in conjunction with 'landscape' or
fantasai@213 1947 'portrait' to indicate both size and orientation.</p>
fantasai@213 1948
fantasai@213 1949 <h4>Some examples:</h4>
fantasai@213 1950
fantasai@213 1951 <div class="example">
fantasai@213 1952 <pre>
fantasai@213 1953 @page {
fantasai@213 1954 size: A4 landscape;
fantasai@213 1955 }
fantasai@213 1956 </pre>
fantasai@213 1957
fantasai@213 1958 <p>The above example sets the width of the page box to be 297mm and the height to
fantasai@213 1959 be 210mm. The page box in this example should be rendered on a page sheet size
fantasai@213 1960 of 210 mm by 297 mm.</p>
fantasai@213 1961 </div>
fantasai@213 1962
fantasai@213 1963 <div class="example">
fantasai@213 1964
fantasai@213 1965 <p>In the following example, the outer edges of the page box will align with the
fantasai@213 1966 page. The percentage value on the <span class="property">'margin'</span>
fantasai@213 1967 property is relative to the page size so if the page sheet dimensions are 210mm
fantasai@213 1968 x 297mm (i.e., A4), the margins are 21mm and 29.7mm. Assuming there are no page
fantasai@213 1969 borders or padding set in the UA default style sheet, the resulting page area
fantasai@213 1970 is 189mm by 367.3mm (210mm-21mm by 297mm-29.7mm).</p>
fantasai@213 1971 <pre>
fantasai@213 1972 @page {
fantasai@213 1973 size: auto;/* auto is the initial value */
fantasai@213 1974 margin: 10%;
fantasai@213 1975 }
fantasai@213 1976 </pre>
fantasai@213 1977 </div>
fantasai@213 1978
fantasai@213 1979 <div class="example">
fantasai@213 1980 <pre>
fantasai@213 1981 @page {
fantasai@213 1982 size: 8.5in 11in;/* width height */
fantasai@213 1983 }
fantasai@213 1984 </pre>
fantasai@213 1985
fantasai@213 1986 <p>The above example sets the width of the page box to be 8.5 inches and the
fantasai@213 1987 height to be 11 inches. This indicates that the page sheet size should be
fantasai@213 1988 8.5"x11" and the orientation 'portrait'.</p>
fantasai@213 1989 </div>
fantasai@213 1990
fantasai@213 1991 <h4 id="page-size-media-query">Media Queries</h4>
fantasai@213 1992
fantasai@213 1993 <p>This section is informative.</p>
fantasai@213 1994
fantasai@213 1995 <p>By using Media Queries [[MEDIAQ]], one style sheet can express different
fantasai@213 1996 stylistic preferences for different page sizes. Consider this example:</p>
fantasai@213 1997
fantasai@213 1998 <div class="example" style="font-size: 10pt;">
fantasai@213 1999 <pre>
simon@6956 2000 /* style sheet for "A4" printing */
fantasai@213 2001 @media print and (width: 21cm) and (height: 29.7cm) {
fantasai@213 2002 @page {
fantasai@213 2003 margin: 3cm;
fantasai@213 2004 }
fantasai@213 2005 }
simon@6956 2006
fantasai@213 2007 /* style sheet for "letter" printing */
fantasai@213 2008 @media print and (width: 8.5in) and (height: 11in) {
fantasai@213 2009 @page {
fantasai@213 2010 margin: 1in;
fantasai@213 2011 }
fantasai@213 2012 }
fantasai@213 2013 </pre>
fantasai@213 2014 </div>
fantasai@213 2015
fantasai@213 2016 <p>In the example above, "A4" sheets are given a "3cm" page margin, and "letter"
fantasai@213 2017 sheets are given a "1in" page margin.</p>
fantasai@213 2018
fantasai@528 2019 <h3 id="renderingpages">Rendering page boxes that do not fit a page sheet</h3>
fantasai@213 2020
fantasai@213 2021 <p>If a page box does not match the target page sheet dimensions, the user agent
fantasai@5987 2022 should do one of the following (in order of preference):</p>
fantasai@213 2023
fantasai@213 2024 <ol>
fantasai@213 2025 <li>Render the page box at the indicated size on a larger page sheet.</li>
fantasai@213 2026 <li>Rotate the page box 90° if this will make the page box fit the page sheet.</li>
fantasai@213 2027 <li>Scale the page box to fit the page sheet. (The aspect ratio of the page box
fantasai@213 2028 <em class="RFC2119">should</em> be preserved.)</li>
simon@7568 2029 <li>Graphically "slice" the page box onto multiple page sheets.</li>
fantasai@213 2030 <li>Clip overflowed content (least preferred).</li>
fantasai@213 2031 </ol>
fantasai@213 2032
fantasai@213 2033 <p>The user agent <em class="RFC2119">MAY</em> wish to consult the user before
fantasai@213 2034 performing these operations.</p>
fantasai@213 2035
fantasai@528 2036 <h3 id="positioning-page-box">Positioning the page box on the sheet</h3>
fantasai@213 2037
simon@7568 2038 <p>When the page box is smaller than the page sheet, the user agent <em class="RFC2119">SHOULD</em> either:</p>
fantasai@213 2039
fantasai@213 2040 <ul>
fantasai@213 2041 <li>center the page box on the sheet since this will align double-sided pages
fantasai@213 2042 and avoid accidental loss of information that is printed near the edge of the
fantasai@213 2043 sheet; or</li>
simon@7568 2044 <li>position the page box in the upper left corner of the page sheet
simon@7568 2045 (or another corner,
simon@7568 2046 based on the 'direction' and 'writing-mode' properties of the page box)
simon@7568 2047 as this may minimize media consumption.</li>
fantasai@213 2048 </ul>
fantasai@213 2049
fantasai@213 2050 <p>The user agent <em class="RFC2119">MAY</em> wish to consult the user in this
fantasai@213 2051 regard.</p><!-- "Page selector and page context" -->
fantasai@213 2052
simon@7430 2053 <h2 id="page-breaks">
simon@7430 2054 <a id="pg-br-before-after"></a>
simon@7430 2055 <a id="page-break-before"></a>
simon@7430 2056 <a id="page-break-after"></a>
simon@7430 2057 <a id="page-break-inside"></a>
simon@7430 2058 <a id="breaks-inside"></a>
simon@7430 2059 <a id="orphans"></a>
simon@7430 2060 <a id="widows"></a>
simon@7430 2061 <a id="allowed-pg-brk"></a>
simon@7430 2062 <a id="brk-btw-blocks"></a>
simon@7430 2063 <a id="brk-btw-lines"></a>
simon@7430 2064 <a id="brk-end-block"></a>
simon@7430 2065 <a id="forced-pg-brk"></a>
simon@7430 2066 <a id="best-pg-brk"></a>
simon@7430 2067 Page Breaks
simon@7430 2068 </h2>
fantasai@213 2069
simon@7430 2070 <p>
simon@7493 2071 The CSS Fragmentation Module [[!CSS3-BREAK]] module
simon@7493 2072 defines how and where CSS boxes
simon@7430 2073 can be <i>fragmented</i>, including across page breaks.
simon@7430 2074 It defines a few properties that indicate where the user agent
simon@7430 2075 <em class="RFC2119">MAY</em> or <em class="RFC2119">MUST</em> break pages,
simon@7430 2076 and on what page (left or right) the subsequent content resumes.
simon@7430 2077 Each page break ends layout in the current <a href="#page-box">page box</a>
simon@7430 2078 and causes remaining pieces of the document tree to be laid out
simon@7430 2079 in a new page box.
simon@7430 2080 </p>
fantasai@213 2081
fantasai@213 2082 <h3 id="using-named-pages">Using named pages: 'page'</h3>
fantasai@213 2083 <table class="propdef" summary="property definition">
fantasai@213 2084 <tr>
fantasai@213 2085 <th>Name:
fantasai@213 2086 <td><dfn id="page">page</dfn>
fantasai@213 2087 <tr>
fantasai@213 2088 <th>Value:
fantasai@1053 2089 <td>auto | &lt;identifier&gt;
fantasai@213 2090 <tr>
fantasai@213 2091 <th>Initial:
fantasai@576 2092 <td>auto
fantasai@213 2093 <tr>
fantasai@213 2094 <th>Applies to:
fantasai@7436 2095 <td>boxes that create <a href="http://www.w3.org/TR/css3-break/#btw-blocks">class 1</a> break points
fantasai@213 2096 <tr>
fantasai@213 2097 <th>Inherited:
fantasai@1053 2098 <td>no (but see prose)
fantasai@213 2099 <tr>
fantasai@213 2100 <th>Percentages:
fantasai@213 2101 <td>N/A
fantasai@213 2102 <tr>
fantasai@213 2103 <th>Media:
fantasai@213 2104 <td>paged
fantasai@213 2105 <tr>
fantasai@213 2106 <th>Computed value:
fantasai@213 2107 <td>specified value
fantasai@213 2108 </table>
simon@6956 2109
fantasai@7436 2110 <p>
fantasai@7436 2111 The 'page' property is used to specify a particular type of page (called a <dfn>named page</dfn>)
fantasai@7436 2112 on which an element <em class="RFC2119">MUST</em> be displayed.
fantasai@7436 2113 If necessary, a <i>forced page break</i> is introduced
fantasai@7436 2114 and a new page generated of the specified type.
fantasai@7436 2115
simon@7556 2116 <p class="note">
simon@7556 2117 This page can be styled by using the same type name
simon@7556 2118 in a <a href="#page-selectors">page selector</a>.
simon@7556 2119
fantasai@7436 2120 <p>
simon@7553 2121 Page type names are case-sensitive identifiers.
fantasai@7436 2122 However the ''auto'' value, being a CSS keyword, is
fantasai@7436 2123 <a href="http://www.w3.org/TR/CSS21/syndata.html#characters">ASCII case-insensitive</a>.
fantasai@213 2124
simon@7430 2125 <p>
fantasai@7432 2126 The 'page' property does not inherit.
fantasai@7432 2127 However, if the 'page' value on an element is ''auto'',
simon@7557 2128 then its used value is the value specified
simon@7557 2129 on its nearest ancestor with a non-auto value.
simon@7553 2130 When specified on the root element,
simon@7557 2131 the used value for ''auto'' is the empty string.
fantasai@1053 2132
fantasai@7436 2133 <!-- See http://www.w3.org/TR/2007/WD-css3-gcpm-20070504/#named3 -->
fantasai@213 2134
fantasai@7432 2135 <p>
simon@7560 2136 Because a previous version of this specification
simon@7560 2137 indicated that the 'page' property is inherited,
fantasai@7436 2138 an implementation that inherits the 'page' property
fantasai@7436 2139 and treats ''auto'' as always naming the empty string
simon@7560 2140 remains conformant to CSS Paged Media Level 3.
simon@7560 2141 Note that this exception will be removed in Level 4.
fantasai@7436 2142 Therefore authors should not explicitly specify the ''auto'' value
fantasai@7436 2143 on a descendant of an element with a non-''auto'' value,
fantasai@7436 2144 as the resulting behavior will be unpredictable.
fantasai@7436 2145
simon@7556 2146 <p>
simon@7556 2147 The 'page' property works as follows:
simon@7556 2148
simon@7556 2149 <ol>
simon@7556 2150
simon@7556 2151 <li>
simon@7556 2152 First, any ''auto'' values are resolved against non-''auto'' ancestors
simon@7556 2153 (as specified above).
simon@7556 2154
simon@7556 2155 <li>
simon@7556 2156 Next,
simon@7556 2157 a <dfn>start 'page' value</dfn> and <dfn>end 'page' value</dfn>
simon@7556 2158 is determined for each box
simon@7609 2159 as the value (if any) propagated from
simon@7609 2160 its first or last child box (respectively),
simon@7556 2161 else the used value on the box itself.
simon@7609 2162 A child propagates its own
simon@7609 2163 <i title="start page value">start</i> or <i>end 'page' value</i>
simon@7556 2164 if and only if the 'page' property applies to it.
simon@7556 2165
simon@7609 2166 <p class="note">
simon@7609 2167 Note:
simon@7609 2168 A first or last child <em>box</em> is not always generated by
simon@7609 2169 a first or last child <em>element</em>.
simon@7609 2170 For example,
simon@7609 2171 an element could only have a previous sibling with 'display: none'
simon@7609 2172 which does not generate any box.
simon@7609 2173
simon@7556 2174 <li>
simon@7558 2175 The first printed page’s type is the <i>start 'page' value</i> of the root.
simon@7558 2176
simon@7558 2177 <li>
simon@7556 2178 If for any two boxes meeting at a <a href="http://www.w3.org/TR/css3-break/#btw-blocks">Class 1</a> break point,
simon@7556 2179 the <i>end 'page' value</i> of the box preceding the break
simon@7556 2180 and <i>start 'page' value</i> of the box succeeding the break
simon@7556 2181 do not match,
simon@7556 2182 then a page break is forced between the two boxes,
simon@7556 2183 and content after the break resumes on a page box of the named type.
simon@7556 2184 </ol>
simon@7556 2185
simon@7556 2186 <p class="note">
simon@7556 2187 Essentially, the two 'page' values compared are those from the deepest boxes
simon@7556 2188 meeting at the class 1 break point,
simon@7556 2189 ignoring any subtrees rooted by boxes to which the 'page' property does not apply.
simon@7556 2190
fantasai@7436 2191 <p>See [[!CSS3-BREAK]] for additional details on page breaks.
fantasai@1054 2192
fantasai@213 2193 <div class="example">
fantasai@213 2194
fantasai@213 2195 <p>In this example, the two tables are rendered on landscape pages (indeed, on the
fantasai@213 2196 same page, if they fit). The page type "narrow" is used for the &lt;p&gt; after
fantasai@213 2197 the second table, as the page properties for the table element are no longer in
fantasai@213 2198 effect:</p>
fantasai@213 2199 <pre>
fantasai@213 2200 @page narrow { size: 9cm 18cm }
fantasai@213 2201 @page rotated { size: landscape }
fantasai@213 2202 div { page: narrow }
fantasai@213 2203 table { page: rotated }
fantasai@213 2204 </pre>with this document:
fantasai@213 2205 <pre>
fantasai@213 2206 &lt;div&gt;
fantasai@213 2207 &lt;table&gt;...&lt;/table&gt;
fantasai@213 2208 &lt;table&gt;...&lt;/table&gt;
fantasai@213 2209 &lt;p&gt;This text is rendered on a 'narrow' page&lt;/p&gt;
fantasai@213 2210 &lt;/div&gt;
fantasai@213 2211 </pre>
fantasai@213 2212 </div>
fantasai@213 2213
fantasai@6813 2214 <div class="example">
fantasai@6813 2215 <p>In Japanese documents, sometimes different parts of a single document
fantasai@6813 2216 will have different <i lang="ja-Latn">kihon hanmen</i>. [[JLREQ]]
fantasai@6813 2217 The 'page' property, together with ''@page'' rules specifying different page widths,
fantasai@6813 2218 can accomodate this type of layout:
fantasai@6813 2219 <pre>
fantasai@6813 2220 &lt;!DOCTYPE html>
fantasai@6813 2221 &lt;html lang="ja">
fantasai@6813 2222 &lt;style>
fantasai@6813 2223 html { writing-mode: vertical-rl;
fantasai@6813 2224 line-height: 1.6; }
fantasai@6813 2225 .main { page: main;
fantasai@6813 2226 columns: 2; column-gap: 1rem; }
fantasai@6813 2227 .index { page: index;
fantasai@6813 2228 columns: 3; column-gap: 1rem; }
fantasai@6813 2229 @page { margin: auto; /* center kihon hanmen on page */
fantasai@6813 2230 width: 40rem; } /* 1.6 &times; 25 lines */
fantasai@6813 2231 @page main { height: 61rem; } /* 2 &times; 30 chars + 1 &times; gap */
fantasai@6813 2232 @page index { height: 62rem; } /* 3 &times; 20 chars + 2 &times; gap */
fantasai@6813 2233 &lt;/style>
fantasai@6813 2234 &lt;section class="main"> ... &lt;/section>
fantasai@6813 2235 &lt;section class="index"> ... &lt;/section>
fantasai@6813 2236 &lt;/html>
fantasai@6813 2237 </pre>
fantasai@6813 2238 </div>
fantasai@6813 2239
fantasai@213 2240
fantasai@566 2241 <h2 id="image-properties">Image Properties</h2>
fantasai@213 2242
simon@7428 2243 <p class="note">This section has been moved to [[CSS3-IMAGES]].</p>
fantasai@213 2244
fantasai@563 2245 <h2 class="no-num" id="properties-list">Appendix A: Applicable CSS2.1 Properties</h2>
fantasai@213 2246
simon@7573 2247 <h3 class="no-num" id="page-property-list">
simon@7573 2248 CSS 2.1 Properties that apply within the page context</h3>
fantasai@213 2249
simon@7573 2250 <p>
simon@7573 2251 This list is described in the
simon@7573 2252 <a href="#page-properties">Page Properties</a> section.
fantasai@213 2253
fantasai@213 2254 <table class="property-list">
fantasai@561 2255 <tbody>
fantasai@5976 2256 <tr><td rowspan="2"><a href="http://www.w3.org/TR/CSS21/visuren.html#direction">bidi properties</a>
fantasai@563 2257 <td>direction
fantasai@563 2258 <tbody>
fantasai@5976 2259 <tr><td rowspan="6"><a href="http://www.w3.org/TR/CSS21/colors.html#background-properties">background properties</a>
fantasai@561 2260 <td>background-color
fantasai@561 2261 <tr><td>background-image
fantasai@561 2262 <tr><td>background-repeat
fantasai@561 2263 <tr><td>background-attachment
fantasai@561 2264 <tr><td>background-position
fantasai@561 2265 <tr><td>background
fantasai@561 2266 <tbody>
fantasai@5976 2267 <tr><td rowspan="20"><a href="http://www.w3.org/TR/CSS21/box.html#border-properties">border properties</a>
fantasai@561 2268 <td>border-top-width
fantasai@561 2269 <tr><td>border-right-width
fantasai@561 2270 <tr><td>border-bottom-width
fantasai@561 2271 <tr><td>border-left-width
fantasai@561 2272 <tr><td>border-width
fantasai@561 2273 <tr><td>border-top-color
fantasai@561 2274 <tr><td>border-right-color
fantasai@561 2275 <tr><td>border-bottom-color
fantasai@561 2276 <tr><td>border-left-color
fantasai@561 2277 <tr><td>border-color
fantasai@561 2278 <tr><td>border-top-style
fantasai@561 2279 <tr><td>border-right-style
fantasai@561 2280 <tr><td>border-bottom-style
fantasai@561 2281 <tr><td>border-left-style
fantasai@561 2282 <tr><td>border-short-style
fantasai@561 2283 <tr><td>border-top
fantasai@561 2284 <tr><td>border-right
fantasai@561 2285 <tr><td>border-bottom
fantasai@561 2286 <tr><td>border-left
fantasai@561 2287 <tr><td>border
fantasai@561 2288 <tbody>
fantasai@5976 2289 <tr><td rowspan="2"><a href="http://www.w3.org/TR/CSS21/generate.html#counters">counter properties</a>
fantasai@561 2290 <td>counter-reset
fantasai@561 2291 <tr><td>counter-increment
fantasai@561 2292 <tbody>
fantasai@5976 2293 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/colors.html#propdef-color">color</a>
fantasai@561 2294 <tbody>
fantasai@5976 2295 <tr><td rowspan="6"><a href="http://www.w3.org/TR/CSS21/fonts.html">font properties</a>
fantasai@561 2296 <td>font-family
fantasai@563 2297 <tr><td>font-size
fantasai@561 2298 <tr><td>font-style
fantasai@561 2299 <tr><td>font-variant
fantasai@561 2300 <tr><td>font-weight
fantasai@561 2301 <tr><td>font
fantasai@561 2302 <tbody>
fantasai@5976 2303 <tr><td rowspan="3"><a href="http://www.w3.org/TR/CSS21/visudet.html#the-height-property">height</a> <a href="http://www.w3.org/TR/CSS21/visudet.html#min-max-heights">properties</a>
fantasai@3574 2304 <td>height
fantasai@3574 2305 <tr><td>min-height
fantasai@3574 2306 <tr><td>max-height
fantasai@3574 2307 <tbody>
fantasai@5976 2308 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visudet.html#line-height">line-height</a>
fantasai@561 2309 <tbody>
fantasai@5976 2310 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/box.html#margin-properties">margin properties</a>
fantasai@561 2311 <td>margin-top
fantasai@561 2312 <tr><td>margin-right
fantasai@561 2313 <tr><td>margin-bottom
fantasai@561 2314 <tr><td>margin-left
fantasai@561 2315 <tr><td>margin
fantasai@561 2316 <tbody>
fantasai@5976 2317 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/ui.html#dynamic-outlines">outline properties</a>
fantasai@563 2318 <td>outline-width
fantasai@563 2319 <tr><td>outline-style
fantasai@563 2320 <tr><td>outline-color
fantasai@563 2321 <tr><td>outline
fantasai@563 2322 <tbody>
fantasai@5976 2323 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/box.html#padding-properties">padding properties</a>
fantasai@561 2324 <td>padding-top
fantasai@561 2325 <tr><td>padding-right
fantasai@561 2326 <tr><td>padding-bottom
fantasai@561 2327 <tr><td>padding-left
fantasai@561 2328 <tr><td>padding
fantasai@561 2329 <tbody>
fantasai@5976 2330 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/generate.html#quotes-specify">quotes</a>
fantasai@561 2331 <tbody>
simon@7567 2332 <tr><td rowspan="7"><a href="http://www.w3.org/TR/CSS21/text.html">text properties</a>
simon@7567 2333 <td>letter-spacing
fantasai@561 2334 <tr><td>text-align
fantasai@561 2335 <tr><td>text-decoration
fantasai@563 2336 <tr><td>text-indent
fantasai@561 2337 <tr><td>text-transform
fantasai@561 2338 <tr><td>white-space
fantasai@563 2339 <tr><td>word-spacing
fantasai@561 2340 <tbody>
fantasai@5976 2341 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visufx.html#visibility">visibility</a>
fantasai@3574 2342 <tbody>
fantasai@5976 2343 <tr><td rowspan="3"><a href="http://www.w3.org/TR/CSS21/visudet.html#the-width-property">width</a> <a href="http://www.w3.org/TR/CSS21/visudet.html#min-max-widths">properties</a>
fantasai@3574 2344 <td>width
fantasai@3574 2345 <tr><td>min-width
fantasai@3574 2346 <tr><td>max-width
fantasai@213 2347 </table>
fantasai@213 2348
fantasai@562 2349
simon@7573 2350 <h3 class="no-num" id="margin-property-list">
simon@7573 2351 CSS 2.1 properties that apply within the margin contexts</h3>
fantasai@213 2352
simon@7573 2353 <p>
simon@7573 2354 This list is described in the
simon@7573 2355 <a href="#page-properties">Page Properties</a> section.
fantasai@562 2356
fantasai@213 2357 <table class="property-list">
fantasai@561 2358 <tbody>
fantasai@5976 2359 <tr><td rowspan="2"><a href="http://www.w3.org/TR/CSS21/visuren.html#direction">bidi properties</a>
fantasai@563 2360 <td>direction
fantasai@563 2361 <tr><td>unicode-bidi
fantasai@563 2362 <tbody>
fantasai@5976 2363 <tr><td rowspan="6"><a href="http://www.w3.org/TR/CSS21/colors.html#background-properties">background properties</a>
fantasai@561 2364 <td>background-color
fantasai@561 2365 <tr><td>background-image
fantasai@561 2366 <tr><td>background-repeat
fantasai@561 2367 <tr><td>background-attachment
fantasai@561 2368 <tr><td>background-position
fantasai@561 2369 <tr><td>background
fantasai@561 2370 <tbody>
fantasai@5976 2371 <tr><td rowspan="20"><a href="http://www.w3.org/TR/CSS21/box.html#border-properties">border properties</a>
fantasai@561 2372 <td>border-top-width
fantasai@561 2373 <tr><td>border-right-width
fantasai@561 2374 <tr><td>border-bottom-width
fantasai@561 2375 <tr><td>border-left-width
fantasai@561 2376 <tr><td>border-width
fantasai@561 2377 <tr><td>border-top-color
fantasai@561 2378 <tr><td>border-right-color
fantasai@561 2379 <tr><td>border-bottom-color
fantasai@561 2380 <tr><td>border-left-color
fantasai@561 2381 <tr><td>border-color
fantasai@561 2382 <tr><td>border-top-style
fantasai@561 2383 <tr><td>border-right-style
fantasai@561 2384 <tr><td>border-bottom-style
fantasai@561 2385 <tr><td>border-left-style
fantasai@561 2386 <tr><td>border-short-style
fantasai@561 2387 <tr><td>border-top
fantasai@561 2388 <tr><td>border-right
fantasai@561 2389 <tr><td>border-bottom
fantasai@561 2390 <tr><td>border-left
fantasai@561 2391 <tr><td>border
fantasai@561 2392 <tbody>
fantasai@5976 2393 <tr><td rowspan="2"><a href="http://www.w3.org/TR/CSS21/generate.html#counters">counter properties</a>
fantasai@561 2394 <td>counter-reset
fantasai@561 2395 <tr><td>counter-increment
fantasai@561 2396 <tbody>
fantasai@561 2397 <tr><td colspan="2"><a href="">content</a>
fantasai@561 2398 <tbody>
fantasai@5976 2399 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/colors.html#propdef-color">color</a>
fantasai@561 2400 <tbody>
fantasai@5976 2401 <tr><td rowspan="6"><a href="http://www.w3.org/TR/CSS21/fonts.html">font properties</a>
fantasai@561 2402 <td>font-family
fantasai@563 2403 <tr><td>font-size
fantasai@561 2404 <tr><td>font-style
fantasai@561 2405 <tr><td>font-variant
fantasai@561 2406 <tr><td>font-weight
fantasai@561 2407 <tr><td>font
fantasai@561 2408 <tbody>
fantasai@5976 2409 <tr><td rowspan="3"><a href="http://www.w3.org/TR/CSS21/visudet.html#the-height-property">height</a> <a href="http://www.w3.org/TR/CSS21/visudet.html#min-max-heights">properties</a>
fantasai@563 2410 <td>height
fantasai@563 2411 <tr><td>min-height
fantasai@563 2412 <tr><td>max-height
fantasai@561 2413 <tbody>
fantasai@5976 2414 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visudet.html#line-height">line-height</a>
fantasai@561 2415 <tbody>
fantasai@5976 2416 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/box.html#margin-properties">margin properties</a>
fantasai@561 2417 <td>margin-top
fantasai@561 2418 <tr><td>margin-right
fantasai@561 2419 <tr><td>margin-bottom
fantasai@561 2420 <tr><td>margin-left
fantasai@561 2421 <tr><td>margin
fantasai@561 2422 <tbody>
fantasai@5976 2423 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/ui.html#dynamic-outlines">outline properties</a>
fantasai@563 2424 <td>outline-width
fantasai@563 2425 <tr><td>outline-style
fantasai@563 2426 <tr><td>outline-color
fantasai@563 2427 <tr><td>outline
fantasai@563 2428 <tbody>
fantasai@5976 2429 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visufx.html#overflow">overflow</a>
fantasai@563 2430 <tbody>
fantasai@5976 2431 <tr><td rowspan="5"><a href="http://www.w3.org/TR/CSS21/box.html#padding-properties">padding properties</a>
fantasai@561 2432 <td>padding-top
fantasai@561 2433 <tr><td>padding-right
fantasai@561 2434 <tr><td>padding-bottom
fantasai@561 2435 <tr><td>padding-left
fantasai@561 2436 <tr><td>padding
fantasai@561 2437 <tbody>
fantasai@5976 2438 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/generate.html#quotes-specify">quotes</a>
fantasai@563 2439 <tbody>
fantasai@5976 2440 <tr><td rowspan="7"><a href="http://www.w3.org/TR/CSS21/text.html">text properties</a>
fantasai@563 2441 <td>letter-spacing
fantasai@561 2442 <tr><td>text-align
fantasai@561 2443 <tr><td>text-decoration
fantasai@563 2444 <tr><td>text-indent
fantasai@561 2445 <tr><td>text-transform
fantasai@561 2446 <tr><td>white-space
fantasai@563 2447 <tr><td>word-spacing
fantasai@563 2448 <tbody>
fantasai@5976 2449 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visudet.html#line-height">vertical-align</a>
fantasai@561 2450 <tbody>
fantasai@5976 2451 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visufx.html#visibility">visibility</a>
fantasai@561 2452 <tbody>
fantasai@5976 2453 <tr><td rowspan="3"><a href="http://www.w3.org/TR/CSS21/visudet.html#the-width-property">width</a> <a href="http://www.w3.org/TR/CSS21/visudet.html#min-max-widths">properties</a>
fantasai@563 2454 <td>width
fantasai@563 2455 <tr><td>min-width
fantasai@563 2456 <tr><td>max-width
fantasai@561 2457 <tbody>
fantasai@5976 2458 <tr><td colspan="2"><a href="http://www.w3.org/TR/CSS21/visuren.html#z-index">z-index</a>
fantasai@213 2459 </table>
fantasai@213 2460
fantasai@552 2461 <h2 class="no-num" id="transfer-possibilities">Appendix B: Transfer Possibilities</h2>
fantasai@552 2462
fantasai@552 2463 <p>Often, but not always, the page box has a one-to-one correspondence to the
fantasai@552 2464 physical surface onto which the document is ultimately rendered. The CSS3 page
fantasai@552 2465 model specifies formatting within the page box, but it is the user agent's
fantasai@552 2466 responsibility to transfer the page box to the sheet. Some user agent transfer
fantasai@552 2467 possibilities that are not addressed by CSS3 include:</p>
fantasai@552 2468
fantasai@552 2469 <ul id="complex-usecases">
fantasai@552 2470 <li>Transferring one page box to one sheet (e.g. single-sided printing);</li>
fantasai@552 2471 <li>Transferring two page boxes to the front and back surfaces of the same
fantasai@552 2472 sheet (e.g. double-sided printing);</li>
fantasai@552 2473 <li>Transferring N (small) page boxes to one sheet (called "N-up");</li>
fantasai@552 2474 <li>Transferring one (large) page box to N x M sheets (called "tiling");</li>
fantasai@552 2475 <li>Creating signatures. A <dfn>signature</dfn> is a group of pages printed on
fantasai@552 2476 a sheet, which, when folded and trimmed like a book, appear in their proper
fantasai@552 2477 sequence;</li>
fantasai@552 2478 <li>Printing one document to multiple output trays;</li>
fantasai@552 2479 <li>Generating files containing print instructions.</li>
fantasai@552 2480 </ul>
fantasai@552 2481
simon@7493 2482 <h2 class="no-num" id="changes">Changes</h2>
simon@7493 2483
simon@7493 2484 <p>
simon@7493 2485 Changes since the <a href="http://www.w3.org/TR/2006/WD-css3-page-20061010/">10 October 2006 Working Draft</a> are:
simon@7493 2486 </p>
simon@7493 2487
simon@7493 2488 <ul>
simon@7558 2489 <li>The first printed page can be <a href="#using-named-pages">named</a>.
simon@7558 2490
simon@7493 2491 <li>The '':blank'' <a href="#pseudo-classes">pseudo-class</a> was imported
simon@7493 2492 from the <a href="http://dev.w3.org/csswg/css3-gcpm/">Generated Content for Paged Media</a> module.
simon@7493 2493
simon@7493 2494 <li>''@page'' rules can now take multiple comma separated selectors,
simon@7493 2495 each selector can have multiple pseudo-classes.
simon@7493 2496
simon@7493 2497 <div class="example">
simon@7493 2498 <pre>@page :first, :blank { @bottom-center { content: none } }</pre>
simon@7493 2499 <pre>@page :first:left { @bottom-left { content: none } }</pre>
simon@7493 2500 </div>
simon@7493 2501
simon@7493 2502 <li>Margin boxes are renamed <a href="#margin-boxes">page-margin boxes</a>,
simon@7493 2503 to avoid confusion with the margin area of each box.
simon@7493 2504
simon@7493 2505 <li>The <a href="#variable-sizing">Variable Dimension</a>
simon@7493 2506 layout rules for page-margin boxes have been much simplified
simon@7493 2507 to not require quadratic optimization.
simon@7493 2508
simon@7493 2509 <li>The relative <a href="#painting">painting order</a>
simon@7493 2510 of page-margin boxes and page content has changed.
simon@7493 2511
simon@7493 2512 <li>The description of page breaks and definition of related properties
simon@7493 2513 (except for the 'page' property)
simon@7493 2514 have been moved to the CSS Fragmentation Module. [[!CSS3-BREAK]]
simon@7493 2515
simon@7493 2516 <li>The 'fit' and 'fit-position' properties
simon@7493 2517 are renamed to 'object-fit' and 'object-position',
simon@7493 2518 redefined to enable additional use cases,
simon@7493 2519 and moved to the CSS3 Image Values and Replaced Content module.
simon@7493 2520 [[CSS3-IMAGES]]
simon@7493 2521
simon@7493 2522 <li>Many miscellaneous clarifications
simon@7493 2523 and editorial improvements have been incorporated.
simon@7493 2524
simon@7493 2525 </ul>
simon@7493 2526
simon@7493 2527
fantasai@213 2528 <h2 class="no-num" id="references">References</h2>
fantasai@213 2529
fantasai@213 2530 <h3 class="no-num" id="normative-references">Normative References</h3><!--normative-->
fantasai@213 2531
fantasai@213 2532 <h3 class="no-num" id="informative-references">Informative References</h3><!--informative-->
fantasai@213 2533 </div>
fantasai@213 2534 </div>
fantasai@213 2535 </body>
fantasai@213 2536 </html>

mercurial