css3-page/Overview.src.html

Thu, 21 Feb 2013 01:26:52 +0100

author
Simon Sapin <simon.sapin@exyr.org>
date
Thu, 21 Feb 2013 01:26:52 +0100
changeset 7513
0dff950123a2
parent 7511
5a4a03bb378c
child 7536
d88e561c0b07
permissions
-rwxr-xr-x

[css3-page] Rewrite page selector specificity for multiple pseudo-classes.

Update to Selectors 4 language, while we’re at it.

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

mercurial