8000 csswg-drafts/css-gcpm/Overview.src.html at e0f36323220d485b0858132c9f744158ea7c47e7 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1313 lines (983 loc) · 45.4 KB

File metadata and controls

1313 lines (983 loc) · 45.4 KB
<h1>CSS Generated Content for Paged Media Module</h1>
<pre class='metadata'>
Status: ED
Shortname: css-gcpm
Level: 3
Group: csswg
ED: http://dev.w3.org/csswg/css-gcpm/
Editor: Dave Cramer, Hachette Livre, dave.cramer@hbgusa.com
Former Editor: Håkon Wium Lie, Opera Software
Link defaults: css-content-3 (property) counter-increment, css-content-3 (property) counter-reset, css21 (property) string, css21 (property) max-height
Abstract: Books and other paged media often use special techniques to display information. Content may be moved to or generated for special areas of the page, such as running heads or footnotes. Generated content within pages, such as tab leaders or cross-references, helps readers navigate within and between pages.
Previous version: https://hg.csswg.org/drafts/raw-file/6a5c44d11c2b/css-gcpm/Overview.html
Previous version: http://www.w3.org/TR/2011/WD-css3-gcpm-20111129/
!Issue Tracking: <a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=CSS&component=Generated%20Content%20for%20Paged%20Media">W3C Bugzilla</a>
Ignored Terms: content-list,
</pre>
<h2 class="no-num" id="introduction">
Introduction
</h2>
Paged media have many <a href="http://w3c.github.io/dpub-pagination/index.html">special requirements</a> for the display of document content, which have evolved over the long history of printed books. Running headers and footers function as aids to navigation. Notes may appear at the bottom of the page, as footnotes. The properties of pages themselves may change based on their content or position in the document. Leaders visually connect related content. Cross-references may require generated text. Some paged media formats such as PDF use bookmarks for navigation.
This module defines new properties and values, so that authors may bring these techniques to paged media.
<!--page areas-->
<h2 id="running-headers-and-footers">
Running headers and footers
</h2>
[[CSS3PAGE]] describes the sixteen page margin boxes which can be used for running headers and footers, but does not describe a mechanism for inserting content in those boxes. This module provides two methods for for doing so. <dfn lt="named string">Named strings</dfn> copy text for reuse in margin boxes. <dfn id="running-elements0">Running elements</dfn> move elements (complete with style and structure) from the document to margin boxes.
<h3 id="named-strings">
Named strings
</h3>
The 'string-set' property copies the text content of an element into a ''named string'', which functions as a variable. The text content of this named string can be retrieved using the ''string()'' function. Since these variables may change on a given page, an optional second value for the ''string()'' function allows authors to choose which value on a page is used.
<h4 id="setting-named-strings-the-string-set-pro">
The string-set property
</h4>
<pre class="propdef">
Name: <dfn id="string-set">string-set</dfn>
Value: [[ <<custom-ident>> <<content-list>>] [, <<custom-ident>> <<content-list>>]* ] | none
Initial: none
Applies to: all elements, but not pseudo-elements
Inherited: no
Percentages: N/A
Media: all
Computed value: specified value
</pre>
The 'string-set' property contains one or more pairs, each consisting of an custom identifier (the name of the named string) followed by a ''content-list'' describing how to construct the value of the named string.
''content-list'' expands to one or more of the following values, in any order.
<pre class="prod">
<dfn id="content-list">content-list</dfn> = [ &lt;string> | &lt;counter()> | &lt;counters()> | &lt;content()> | attr(&lt;identifier>) ]+
</pre>
<dl dfn-type="value" dfn-for="content-list">
<dt> &lt;string> </dt>
<dd> A <a href="http://www.w3.org/TR/CSS21/syndata.html#strings">string</a>, as defined in [[CSS21]] </dd>
<dt> &lt;counter()> </dt>
<dd> A <a href="http://www.w3.org/TR/CSS21/syndata.html#counter">counter()</a> function, as described in [[CSS21]].</dd>
<dt> &lt;counters()> </dt>
<dd> A <a href="http://www.w3.org/TR/CSS21/syndata.html#counter">counters()</a> function, as described in [[CSS21]].</dd>
<dt>content()</dt>
<dd>The ''content()'' function, described below.</dd>
<dt>attr(&lt;identifier>)</dt>
<dd>Returns the string value of the attribute &lt;identifier>, as defined in [[CSS3VAL]]</dd>
</dl>
<h5 id="content-function-header">The ''content()'' function</h5>
<pre class="prod">
<dfn>content()</dfn> = content([text | before | after | first-letter ])
</pre>
<p class="issue">How do we define the default value for this function?</p>
<dl dfn-type="value" dfn-for="content()">
<dt>text</dt>
<dd>The string value of the element, determined as if <code>white-space: normal</code> had been set. This is the default value</dd>
<dt>before</dt>
<dd>The string value of the <code>::before</code> pseudo-element, determined as if <code>white-space: normal</code> had been set. </dd>
<dt>after</dt>
<dd>The string value of the <code>::after</code> pseudo-element, determined as if <code>white-space: normal</code> had been set. </dd>
<dt>first-letter</dt>
<dd>The first letter of the element, as defined for the <code><a href="http://www.w3.org/TR/css3-selectors/#first-letter">::first-letter</a></code> pseudo-element </dd>
</dl>
The content values of named strings are assigned at the point when the content box of the element is first created (or would have been created if the element’s display value is none). The <dfn>entry value</dfn> for a page is the assignment in effect at the end of the previous page. The <dfn>exit value</dfn> for a page is the assignment in effect at the end of the current page.
Whenever the value of the element changes, the value of the named string(s) is updated. User agents must be able to recall many values of the named string, as the ''string()'' function can return past, current, or future values of the assignment.
<div class="example">
HTML:
<pre>
&lt;h1>Loomings&lt;/h1>
</pre>
CSS:
<pre>
h1::before { content: 'Chapter ' counter(chapter); }
h1 { string-set: header content(before) ':' content(text); }
h1::after { content: '.'; }
</pre>
The value of the named string “header” will be “Chapter 1: Loomings”.
</div>
<div class="example">
HTML:
<pre>
&lt;section title="Loomings">
</pre>
CSS:
<pre>
section { string-set: header attr(title) }
</pre>
The value of the “header” string will be “Loomings”.
</div>
<h4 id="using-named-strings">
The ''string()'' function
</h4>
The ''string()'' function is used to copy the value of a named string to the document, via the 'content' property. This function requires one argument, the name of the named string. Since the value of a named string may change several times on a page (as new instances of the element defining the string appear) an optional second argument indicates which value of the named string should be used.
<pre class="prod">
<dfn>string()</dfn> = string( <<custom-ident>> [ , [ first | start | last | first-except] ]? )
</pre>
The second argument of the ''string()'' function is one of the following keywords:
<dl dfn-type="value" dfn-for="string()">
<dt id="string-first">first</dt>
<dd>The value of the first assignment on the page is used. If there is no assignment on the page, the ''entry value'' is used. <code>first</code> is the default value.</dd>
<dt id="string-start">start</dt>
<dd>If the element is the first element on the page, the value of the first assignment is used. Otherwise the ''entry value'' is used. The ''entry value'' may be empty if the element hasn’t yet appeared. </dd>
<dt id="string-last">last</dt>
<dd>The ''exit value'' of the named string is used.</dd>
<dt id="string-first-except">first-except</dt>
<dd>This is identical to <code>first</code>, except that the empty string is used on the page where the value is assigned.</dd>
</dl>
<div class="example">
CSS:
<pre>
@page {
size: 15cm 10cm;
margin: 1.5cm;
@top-left {
content: "first: " string(heading, first);
}
@top-center {
content: "start: " string(heading, start);
}
@top-right {
content: "last: " string(heading, last);
}
}
h2 { string-set: heading content() }
</pre>
The following figures show the first, start, and last assignments of the “heading” string on various pages.
<figure>
<img src="using-strings-1.jpg" width="480" alt=""/>
<figcaption>The <a href="#string-start">start</a> value is empty, as the string had not yet been set at the start of the page.</figcaption>
</figure>
<figure>
<img src="using-strings-2.jpg" width="480" alt=""/>
<figcaption>Since the page starts with an h2, the <a href="#string-start">start</a> value is the value of that head.</figcaption>
</figure>
<figure>
<img src="using-strings-3.jpg" width="480" alt=""/>
<figcaption>Since there’s not an h2 at the top of this page, the <a href="#string-start">start</a> value is the ''exit value'' of the previous page.</figcaption>
</figure>
</div>
<!--
<div class="example">
<pre>
Example where element fragments across page boundary
</pre>
</div>
-->
<h3 id="running-elements">
Running elements
</h3>
Many headers and footers cannot be represented only by unformatted text. A book title serving as a running head may contain an italic word, for example. A mechanism is needed to move or copy elements into margin boxes. To do this, we add the ''running()'' value to the position property, and the ''element()'' value to the content property.
<div class="example">
<pre>
@page {
@top { content: element(header); }
}
h1 { position: running(header); }
</pre>
In this example, the <code>h1</code> element is placed in the <code>@top</code> margin box, complete with formatting and any descendant elements. It does not display in the normal document flow.
</div>
<h4 id="running-syntax">
The ''running()'' value
</h4>
<code>position: running(custom-ident)</code> removes the element (and associated ::before and ::after pseudo-elements) from the normal flow, and makes it available to place in a page margin box using ''element()''. The element inherits from its original position in the document, but does not display there.
<pre class="propdef partial">
Name: position
New Values: running()
Media: paged
</pre>
<pre class="prod">
<dfn>running()</dfn> = string( <<custom-ident>> )
</pre>
<!--
<h4 id="alternative-syntax-running">Alternative Proposal from Bert Bos</h4>
-->
<div class="example">
HTML:
<pre>
&lt;p class="rh">&lt;i>Miranda v. Arizona&lt;/i> in Context&lt;/p>
&lt;h2>&lt;i>Miranda v. Arizona&lt;/i> in Context&lt;/h2>
</pre>
CSS:
<pre>
@top-center {
content: element(heading);
}
p.rh {
position: running(heading);
}
p.rh::before {
content: counter(page) ' / ';
}
</pre>
<figure>
<img src="running-element-gcpm_Page_1.jpg" width="480" alt="running header using running elements"/>
<figcaption>Running element in page margin box</figcaption>
</figure>
</div>
<p class="note">The element ''value()'' can only be used in page margin boxes. And it cannot be combined with other possible values for the content property.</p>
<div class="issue">
<p>This idea would be much more useful if we could also copy (rather than just move) elements. That would avoid the duplication of HTML in the example above.
</p>
Bert Bos has proposed an alternative syntax, which allows both moving and copying elements into running heads. In the example below, h2 elements appear in their normal place in the document, but are also copied into running heads.
<div class="example">
<pre>
h2 {
display: block;
running: chapter;
font-size: 18pt;
font-weight: bold;
}
h2:running {
display: inline;
font-size: 11pt;
font-weight: normal;
font-variant: small-caps;
letter-spacing: 1pt;
}
@page {
@top-center {
content: element(chapter);
}
}
</pre>
</div>
<pre class="propdef">
Name: <dfn id="running-property">running</dfn>
Value: <<custom-ident>>
Initial: none
Applies to: elements
Inherited: no
Percentages: N/A
Media: all
Computed value: specified value
</pre>
</div>
<h4 id="element-syntax">
The ''element()'' value
</h4>
The ''element()'' value of the content property places an element (which has been removed from the normal flow via ''running()'') in a page margin box. Whenever the value of the element changes, the value of ''element()'' is updated.
Just as with ''string()'', ''element()'' takes an optional keyword to describe which value should be used in the case of multiple assignments on a page. User agents must be able to recall many values, as ''element()'' can return past, current, or future values of the assignment.
<pre class="propdef partial">
Name: content
New Values: element()
Media: paged
</pre>
<pre class="prod">
<dfn>element()</dfn> = string( <<custom-ident>> [ , [ first | start | last | first-except] ]? )
</pre>
<h2 id="footnotes">
Footnotes
</h2>
Ancillary content may be moved to the bottom or side of a page. A footnote is created when such content moves to the bottom of the page, leaving a reference indicator.
<h3 id="footnote-terms">Terminology</h3>
Footnotes are complex objects (see the <a href="http://www.w3.org/TR/2014/WD-dpub-latinreq-20140313/#footnotes">footnote section</a> at [[dpub-latinreq]]), so it will be helpful to define some terms before proceeding.
<figure>
<img src="footnote-diagram.001.jpg" width="480" alt="page with footnotes"/>
<figcaption>Footnote terminology</figcaption>
</figure>
<dl>
<dt>footnote element</dt>
<dd>The element containing the content of the footnote, which will be removed from the flow and displayed as a footnote.</dd>
<dt>footnote marker (also known as footnote number)</dt>
<dd>A number or symbol adjacent to the footnote body, identifying the particular footnote. The footnote marker should use the same number or symbol as the corresponding footnote call, although the marker may contain additional punctuation.</dd>
<dt>footnote body</dt>
<dd>The footnote marker is placed before the footnote element, and together they represent the footnote body, which will be placed in the footnote area.</dd>
<dt>footnote call (also known as footnote reference)</dt>
<dd>A number or symbol, found in the main text, which points to the footnote body.</dd>
<dt>footnote area</dt>
<dd>The page area used to display footnotes.</dd>
<dt>footnote rule (also known as footnote separator)</dt>
<dd>A horizontal rule is often used to separate the footnote area from the rest of the page. The separator (and the entire footnote area) cannot be rendered on a page with no footnotes.</dd>
</dl>
<h3 id="creating-footnotes">
Creating footnotes
</h3>
An element becomes a footnote by applying <code>float: footnote</code> to that element. This triggers the following actions:
<ol>
<li> The footnote element is removed from the flow, and a <code>::footnote-call</code> pseudo-element is inserted in its place, which serves as a reference to the footnote.</li>
<li> A <code>::footnote-marker</code> pseudo-element, identifying the footnote, is placed at the beginning of the footnote element. Together this is the footnote body.</li>
<li>The ''footnote counter'' is incremented.</li>
<li>The footnote body is placed in the footnote area at the bottom of the page. Footnote elements from a given page are placed in the footnote area of that page in document order.</li>
</ol>
<div class="example">
HTML:
<pre style="word-wrap: break-word; white-space: pre-wrap;">
&lt;p>Though the body was erect, the head was thrown back so that the closed eyes were pointed towards the needle of the tell-tale that swung from a beam in the ceiling.&lt;span class="footnote">The cabin-compass is called the tell-tale, because without going to the compass at the helm, the Captain, while below, can inform himself of the course of the ship.&lt;/span>&lt;/p>
</pre>
CSS:
<pre>
@page {
@footnote {
float: bottom;
}
}
span.footnote { float: footnote; }
</pre>
</div>
<p class="issue">Why is float:bottom used with the footnote area? Floating footnotes to the footnote area, and then floating the footnote area itself, seems overly complex, given that implementations don’t allow the footnote area to float anywhere else. Note that some implementations do allow the footnote area to be absolutely positioned.</p>
<h3 id="footnote-types">
Types of footnotes
</h3>
The following new value of the 'float' property creates a footnote element:
<pre class="propdef partial">
Name: float
New Values: footnote
Media: paged
</pre>
<dl dfn-type="value" dfn-for="float">
<dt><dfn>footnote</dfn></dt>
<dd>each footnote element is placed in the footnote area of the page</dd>
</dl>
The 'footnote-display' property determines whether a footnote is displayed as a block element or inline element.
<pre class="propdef">
Name: <dfn id="propdef-footnote-display">footnote-display</dfn>
Value: block | inline | compact
Initial: block
Applies to: elements
Media: paged
Inherited: no
Percentages: N/A
Computed value: specified value
</pre>
<dl dfn-type="value" dfn-for="propdef-footnote-display">
<dt><dfn id="footnote-display-block">block</dfn></dt>
<dd>The footnote element is placed in the footnote area as a block element</dd>
<dt><dfn id="footnote-display-inline">inline</dfn></dt>
<dd>The footnote element is placed in the footnote area as an inline element</dd>
<dt><dfn id="footnote-display-compact">compact</dfn></dt>
<dd>The user agent determines whether a given footnote element is placed as a block element or an inline element. If two or more footnotes could fit on the same line in the footnote area, they should be placed inline.</dd>
</dl>
<h3 id="footnote-area">
The footnote area
</h3>
A <a href='http://dev.w3.org/csswg/css-page/#page-area'>page area</a> that can be used to display footnotes is described in the <a href='http://dev.w3.org/csswg/css-page/#page-context'>page context</a> using an <code>@footnote</code> rule. This rule defines a box that, if used, will contain all the footnote elements that appear on that page. <!--
We add the following to the <a href="http://dev.w3.org/csswg/css-page/#specializatons-of-ATKEYWORD">page rule grammar</a> in [[CSS3PAGE]]:
<pre class="lexical">
FOOTNOTE_SYM ::= "@footnote"
</pre>
-->
<p class="issue">How would one describe this in the grammar of CSS3-Page?</p>
<h4 id="footnote-area-position">Positioning of the footnote area</h4>
The bottom margin edge of the footnote area is positioned so that it touches the bottom of the page area. The footnote area can only contain footnotes.
<p class="issue">How do footnotes work in multi-column text? Prince uses <code>float: prince-column-footnote</code> to create a footnote at the bottom of a column rather than the bottom of a page.</p>
<p class="issue">Implementations that support footnotes generally support page floats like <code>float: bottom</code>. Page floats should end up above the footnote area. How might this be specified?</p>
<h4 id="footnote-area-size">Size of the footnote area</h4>
The 'max-height' property on the footnote area limits the size of this area, unless the page contains only footnotes (as may happen on the last page of a document).
Since it is undesirable for a page to consist only of footnotes, user agents <em class="RFC2119">may</em> set a default max-height value on the footnote area.
<h3 id="footnote-counters">The Footnote Counter</h3>
The <dfn>footnote counter</dfn> is a predefined <a href="http://dev.w3.org/csswg/css-lists/#counter">counter</a> associated with the footnote element. Its value is the number or symbol used to identify the footnote. This value is used in both the footnote call and the footnote marker. It should be incremented for each footnote.
<h4 id="footnote-counter-values">Values of the footnote counter</h4>
The footnote counter, like other counters, may use any <a href="http://dev.w3.org/csswg/css-counter-styles-3/#counter-style">counter style</a>. Footnotes often use a sequence of symbols.
<div class="example">
<pre>
::footnote-call { content: counter(footnote, symbols('*', '†', '‡', '§')); }
::footnote-marker { content: counter(footnote, symbols('*', '†', '‡', '§')) '. '; }
</pre>
</div>
<h4 id="resetting-footnote-counter">Resetting the footnote counter</h4>
The footnote counter may be reset on each page.
<div class="example">
<pre>
@page {
counter-reset: footnote;
@footnote { … }
}
</pre>
</div>
Note that the value of the footnote counter should depend on the position of the footnote element in the document tree, not where it is eventually placed. A footnote element may sometimes be placed on the page after the footnote call, but the same counter value must be used for both.
<h3 id="footnote-call">
The <code>footnote-call</code> pseudo-element
</h3>
A <code>::footnote-call</code> pseudo-element is inserted in place of the footnote element when the latter is removed from the flow. By default, the content of this pseudo-element is the value of the footnote counter, styled as a superscripted number.
<div class="example">
<pre>
::footnote-call {
content: counter(footnote);
vertical-align: baseline;
font-size: 100%;
line-height: inherit;
font-variant-position: super;
}
</pre>
</div>
<h3 id="footnote-marker">
The <code>footnote-marker</code> pseudo-element
</h3>
The <code>::footnote-marker</code> pseudo-element represents the footnote element’s marker, the number or symbol that identifies each footnote. This pseudo-element behaves like a <code>::marker</code> pseudo-element, as defined in [[CSS3LIST]]. It is placed at the beginning of the superior parent’s content, and is inline by default. The <code>::footnote-marker</code> can be styled just as other <code>::marker</code> elements can be. The default style should include <code>list-style-position: inside</code>.
<div class="example">
<pre>
::footnote-marker {
content: counter(footnote);
}
::footnote-marker::after {
content: '. ';
}
</pre>
</div>
<h3 id="footnote-policy">
Rendering footnotes and <code>footnote policy</code>
</h3>
Rendering footnotes can be complex. If a footnote falls near the bottom of the page, there may not be enough room on the page for the footnote body. The 'footnote-policy' property allows authors some influence over the rendering of difficult pages.
<pre class="propdef">
Name: <dfn id="footnote-policy">footnote-policy</dfn>
Value: auto | line | block
Initial: auto
Applies to: elements
Media: paged
Inherited: no
Percentages: N/A
Computed value: specified value
</pre>
<dl dfn-type="value" dfn-for="footnote-policy">
<dt><dfn>auto</dfn></dt>
<dd>The user agent chooses how to render footnotes, and may place the footnote body on a later page than the footnote reference. A footnote body must never be placed on a page before the footnote reference.</dd>
<dt><dfn id="footnote-policy-line">line</dfn></dt>
<dd>If a given footnote body cannot be placed on the current page due to lack of space, the user agent introduces a forced page break at the start of the line containing the footnote reference, so that both the reference and the footnote body fall on the next page. Note that the user agent must honor <a href="http://dev.w3.org/csswg/css-break/#widows-orphans">widow and orphan</a> settings when doing this, and so may need to insert the page break on an earlier line.</dd>
<dt><dfn>block</dfn></dt>
<dd>As with <a href="#footnote-policy-line">line</a>, except a forced page break is introduced before the paragraph that contains the footnote.</dd>
</dl>
<p class="issue">We need an algorithm for laying out footnotes</p>
<!--
<h4 id="pseudo-code-for-footnotes">
Pseudo-code for processing non-column footnotes
</h4>
let p = total height of any footnotes leftover from previous page
let t = margin-top of @footnote + padding-top of @footnote + border-top of @footnote
let g = total height of content area of page (goal in TeX lingo)
let m = max-height of @footnote (default is 75% of height of page content area)
let h(n) = height of nth footnote on page, as rendered in the footnote area
let f = total height needed for all footnotes on page
[1] at beginning of page, the following amount of space will be needed for footnotes:
f = if (p ne 0) then (p + t) else 0
[2] for n = 1 to (count of footnote elements on page)
f = f + h(n)
When starting a new page, the height of the footnote area is initially zero.
Load a page. If there are no leftover footnotes from previous pages to place, and no footnote elements on the current page, just render the current page. Otherwise,
<ol>
<li> create a footnote area, with the height of the content area set initially to zero, but all other properties as described by @footnote. The width of the footnote area is the width of the content area of the page. </li>
<li> Place any leftover footnotes in the footnote area, thus increasing its height. Continue until running out of leftover footnotes, reaching max height, or reaching height of page (size - top margin - bottom margin). If you still have parts of footnotes left after this process, mark them as leftover footnotes for the next page. </li>
<li> place the footnote area at the bottom of the page, reducing the content area of @page </li>
<li> if page is full of footnotes, go to next page. </li>
<li> If not, start drawing content on the page. if you reach a line with a footnote element, move element to bottom of footnote area. </li>
<li> Place as much of footnote as possible until reaching max height, or page height. </li>
<li> leave footnote-marker at location of footnote element. </li>
<li> increment footnote counter </li>
</ol>
-->
<!--
<h3>Sidenotes</h3>
<h4>Creating sidenotes</h4>
An element becomes a sidenote by applying float: sidenote to that element. This triggers several actions:
<ol>
<li>
The element is removed from the flow.
</li>
<li>
The sidenote element is positioned in the sidenote area, as described below.
</li>
</ol>
Unlike footnotes, calls and markers are not created by default for sidenotes.
<h4>The sidenote area</h4>
A page area that can be used to display sidenotes is described in the page context using an @sidenote rule. This rule defines a box that, if used, will contain the content that has been identified as a sidenote. The position or float properties of this box determines the placement of the sidenote.
-->
<h3 id="future">
Future directions
</h3>
The next level will include sidenotes, column footnotes, and multiple footnote areas.
<!--page selectors-->
<h2 id="the-first-page-pseudo-element">
Selecting Pages
</h2>
<!--should this be in css3-page?-->
A paginated document consists of a sequence of pages. [[CSS3PAGE]] defines <dfn>page selectors</dfn>, which allow the selection of the first page of the document, left and right pages, and blank pages. Here we extend the idea of page selectors to enable the selection of arbitrary document pages.
<h3 id="document-page-selectors">
Page Selectors
</h3>
The ''nth()'' page pseudo-class allows the selection of arbitrary document pages. This pseudo-class takes an argument of the form <a href="http://dev.w3.org/csswg/css-syntax/#anb">An + B</a> as defined in [[CSS3SYN]]. When applied to the default @page rule, ''nth()'' selects the document page whose index matches the argument.
<pre class="prod">
<dfn>nth()</dfn> = ( An+B [of <<custom-ident>>]?)
</pre>
<p class="note">
''nth()'' is not related to the page counter, which may reset and use various numbering schemes.</p>
When the ''nth()'' selector is applied to a named page, and that named page is part of a page-group (see below), it selects the nth page in the page group.
<div class="example">
<pre>
@page :nth(1)
</pre>
This selects the first page of the document.
<pre>
@page :nth(2n)
</pre> This selects all even document pages.
</div>
<h3 id="document-sequence-selectors">
Page groups
</h3>
Many paginated documents have a repeating structure, consisting of many chapters, sections, or articles. The first page of each subdivision often requires special treatment, but [[CSS3PAGE]] doesn’t define a way to select the first page of each chapter (as distinct from the first page of the entire document).
When the 'page' property is applied to an element that also has a forced break property applied, a ''page group'' is created. The <dfn>page group</dfn> is the collection of all pages created by an instance of that element. When a new instance of the element is rendered, a new ''page group'' is started.
A page may be part of several page groups, as a given ''page group'' may have ancestors or descendants that are part of another ''page group''.
<!-- A page group always starts on a new page.
NOT TRUE; NEED TO DESCRIBE
-->
<div class="example">
CSS:
<pre>
div { page: A }
child { page: B }
</pre>
<figure>
<img src="PageGroups.001.jpg" width="480" alt=""/>
<figcaption>A page may be part of several page groups.</figcaption>
</figure>
Note that page 5 can be selected in three ways:
<pre>
@page :nth(5 of A) /* will select 5th page of every &lt;div> */
@page :nth(1 of B) /* will select first page of every &lt;child> */
@page :nth(5) /* will select 5th page of document */
</pre>
</div>
<div class="example">
Consider the following HTML:
<pre>
&lt;div class="chapter">
&lt;h1>Chapter One&lt;/h1>
&lt;p>some text&lt;/p>
&lt;table class="broadside">
...
&lt;/table>
...
&lt;/div>
&lt;div class="chapter">
&lt;h1>Chapter Two&lt;/h1>
&lt;p>some text&lt;/p>
...
&lt;table class="broadside">
...
&lt;/table>
...
&lt;/div>
</pre>
And CSS:
<pre>
div.Chapter {
page: body;
}
div.broadside {
page: broadside;
}
</pre>
In this case, each chapter will form a separate page group. @page:nth(3 of body) will select the third page of each chapter, even if that page happens to use the “broadside” named page. @page:nth(1) will select only the first page of the document, as will @page:first.
</div>
<h2 id="leaders">
Leaders
</h2>
A leader, sometimes known as a tab leader or a dot leader, is a repeating pattern used to visually connect content across horizontal spaces. They are most commonly used in tables of contents, between titles and page numbers. The ''leader()'' function, as a value for the content property, is used to create leaders in CSS. This function takes a string (the leader string), which describes the repeating pattern for the leader.
<pre class="propdef partial">
Name: content
New Values: leader()
Media: paged
</pre>
<pre class="prod">
<dfn>leader()</dfn> = leader( [dotted | solid | space] | <<string>>);
</pre>
Three keywords are shorthand values for common strings:
<dl>
<dt id="dotted-leader">dotted</dt>
<dd>leader('. ')</dd>
<dt id="solid-leader">solid</dt>
<dd>leader('_')</dd>
<dt id="space-leader">space</dt>
<dd>leader(' ')</dd>
<dt id="string-leader">&lt;string></dt>
<dd></dd>
</dl>
<div class="example">
<pre>
ol.toc a::after {
content: leader('.') target-counter(attr(href), page);
}
&lt;h1>Table of Contents&lt;/h1>
&lt;ol class="toc">
&lt;li>&lt;a href="#chapter1">Loomings&lt;/a>&lt;/li>
&lt;li>&lt;a href="#chapter2">The Carpet-Bag&lt;/a>&lt;/li>
&lt;li>&lt;a href="#chapter3">The Spouter-Inn&lt;/a>&lt;/li>
&lt;/ol>
</pre> This might result in: <pre>
Table of Contents
1. Loomings.....................1
2. The Carpet-Bag...............9
3. The Spouter-Inn.............13
</pre>
</div>
<p class="issue">
Do leaders depend on the assumption that the content after the leader is right-aligned (end-aligned)?
</p>
<h3 id="rendering-leaders">
Rendering leaders
</h3>
Consider a line which contains the content before the leader (the “before content”), the leader, and the content after the leader (the “after content”). Leaders obey the following rules:
<ol>
<li>The leader string must appear in full at least once. </li>
<li>The leader should be as long as possible</li>
<li>Visible characters in leaders should vertically align with each other when possible.</li>
<li>Line break characters in the leader string must be ignored.</li>
<li>White space in the leader string follows normal CSS rules.</li>
<li>A leader only appears between the start content and the end content.</li>
<li>A leader only appears on a single line, even if the before content and after content are on different lines. </li>
<li>A leader can’t be the only thing on a line. </li>
</ol>
<h4 id="procedure-leader">
Procedure for rendering leaders
</h4>
<ol>
<li> Lay out the before content, until reaching the line where the before content ends. <pre>
BBBBBBBBBB
BBB
</pre> </li>
<li> The leader string consists of one or more glyphs, and is thus an inline box. A leader is a row of these boxes, drawn from the end edge to the start edge, where only those boxes not overlaid by the before or after content. On this line, draw the leader string, starting from the end edge, repeating as many times as possible until reaching the start edge. <pre>
BBBBBBBBBB
..........
</pre> </li>
<li> Draw the before and after content on top of the leader. If any part of the before or after content overlaps a glyph in a leader string box, that glyph is not displayed.<pre>
BBBBBBBBBB
BBB....AAA
</pre> </li>
<li> If one full copy of the leader string is not visible: <pre>
BBBBBBB
BBBBBBA
</pre> Insert a line break before the after content, draw the leader on the next line, and draw the end content on top <pre>
BBBBBBB
BBBBBB
......A
</pre> </li>
</ol>
<figure>
<img src="leader.001.jpg" width="480" alt="drawing leaders"/>
<figcaption>Procedure for drawing leaders</figcaption>
</figure>
<figure>
<img src="leader.002.jpg" width="480" alt="drawing leaders"/>
<figcaption>Procedure for drawing leaders when the content doesn’t fit on a single line</figcaption>
</figure>
<h2 id="cross-references">
Cross-references
</h2>
<!--why is this in gcpm-->
Many documents contain internal references:
<ul>
<li> See chapter 7 </li>
<li> in section 4.1 </li>
<li> on page 23 </li>
</ul>
Three new values for the content property are used to automatically create these types of cross-references: ''target-counter()'', ''target-counters()'', and ''target-text()''. Each of these displays information obtained from the target end of a link.
<h3 id="target-counter">
The ''target-counter()'' function
</h3>
The ''target-counter()'' function retrieves the value of the innermost counter with a given name. The required arguments are the url of the target and the name of the counter. An optional counter-style argument can be used to format the result.
<p class="note">These functions only take a fragment URL which points to a location in the current document. If there’s no fragment, if the ID referenced isn't there, or if the URL points to an outside document, the user agent must treat that as an error.</p>
<pre class="prod">
<dfn>target-counter()</dfn> = target-counter( <<url>> , <<custom-ident>> [ , <<counter-style>> ]? )
</pre>
<div class="example">
HTML:
<pre>
…which will be discussed on page &lt;a href="#chapter4_sec2">&lt;/a>.
</pre>
CSS:
<pre>
a::after { content: target-counter(attr(href url), page) }
</pre>
Result:
<pre>
…which will be discussed on page 137.
</pre>
</div>
<div class="example">
Page numbers in tables of contents can be generated automatically:
HTML:
<pre>
&lt;nav>
&lt;ol>
&lt;li class="frontmatter">&lt;a href="#pref_01">Preface&lt;/a>&lt;/li>
&lt;li class="frontmatter">&lt;a href="#intr_01">Introduction&lt;/a>&lt;/li>
&lt;li class="bodymatter">&lt;a href="#chap_01">Chapter One&lt;/a>&lt;/li>
&lt;/ol>
&lt;/nav>
</pre>
CSS:
<pre>
.frontmatter a::after { content: leader('.') target-counter(attr(href url), page, lower-roman) }
.bodymatter a::after { content: leader('.') target-counter(attr(href url), page, decimal) }
</pre>
Result:
<pre>
Preface.............vii
Introduction.........xi
Chapter One...........1
</pre>
</div>
<h3 id="target-counters">
The ''target-counters()'' function
</h3>
This functions fetches the value of all counters of a given name from the end of a link, and formats them by inserting a given string between the value of each nested counter.
<pre class="prod">
<dfn>target-counters()</dfn> = target-counter( <<url>> , <<custom-ident>> , <<string>> [ , <<counter-style>> ]? )
</pre>
<div class="example">
<pre>
I have not found a compelling example for target-counters() yet.
</pre>
</div>
<h3 id="target-text">
target-text
</h3>
The ''target-text()'' function retrieves the text value of the element referred to by the URL. An optional second argument specifies what content is retrieved, using the same values as the 'string-set' property above.
<pre class="prod">
<dfn id="target-text-function">target-text()</dfn> = target-counter( <<url>> [ , [ content | before | after | first-letter] ]? )
</pre>
<p class="issue">A simpler syntax has been proposed by fantasai: http://lists.w3.org/Archives/Public/www-style/2012Feb/0745.html</p>
<div class="example">
<pre>
…which will be discussed &lt;a href="#chapter_h1_1">later&lt;/a>.