8000 csswg-drafts/css-content/Overview.html at 49d3d73df19c8577a16595b79ce575619f114648 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
2105 lines (1599 loc) · 73.5 KB

File metadata and controls

executable file
·
2105 lines (1599 loc) · 73.5 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!--*- Mode: Text; fill-column: 95 -*-->
<html lang=en>
<head profile="http://dublincore.org/documents/2008/08/04/dc-html/ ">
<meta content="text/html" http-equiv=Content-Type>
<meta charset=utf-8>
<title>CSS Generated Content Module Level 3</title>
<link href="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS Generated Content Module Level 3" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2014-02-03 name=dcterms.date>
<meta content="Håkon Wium Lie" name=dcterms.creator>
<meta content="Elika J. Etemad" name=dcterms.creator>
<meta content="Ian Hickson" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css3-content/"
name=dcterms.identifier><!--
FIXME when publishing: copy the current default.css and link to
"default.css" rather than "../default.css"
-->
<link href="../default.css" rel=stylesheet type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css"></head>
<!-- TODO:
! * Sync with CSS2.1 and GCPM
! * Clean up descriptions and organize into something coherent
! * place 'property' into marked up property elements
! * similarly with '::pseudo' and examples
! * http://lists.w3.org/Archives/Member/w3c-css-wg/2003JanMar/0170.html
! * string-set and co
! * need to increment the footnote, endnote and section-note counters
! * cross references, as in http://www.w3.org/Style/Group/2001/MO-css3-page-20010205
! * date() and time()
! * drop nesting
!
!-->
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Generated Content Module Level 3</h1>
<h2 class="no-num no-toc">Editor's Draft 3 February 2014</h2>
<dl>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/css3-content/">http://dev.w3.org/csswg/css3-content/</a></dd>
<!-- <dd><a
href="2014/ED-css3-content-20140203">2014/ED-css3-content-20140203</a></dd> -->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-content/">http://www.w3.org/TR/css3-content/</a>
<dt>Previous versions:
<dd><a
href="http://www.w3.org/TR/2003/WD-css3-content-20030514/">http://www.w3.org/TR/2003/WD-css3-content-20030514/</a>
<dt>Feedback:
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss-content%5D%20feedback">www-style@w3.org</a>
with subject line “<kbd>[css-content] <var>… message topic
…</var></kbd>” (<a
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd><a href="mailto:howcome@opera.com">Håkon Wium Lie</a>, Opera
Software
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>,
W3C Invited Expert
<dd><a href="mailto:ian@hixie.ch">Ian Hickson</a>
</dl>
<p>, Opera Software <!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2014 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<details class=annoying-warning open=open> <summary>Obsoletion
Notice</summary>
<p>This specification is not being actively maintained, and should not be
used as a guide for implementations. It may be revived in the future, but
for now should be considered obsolete. <br>
If you have questions or comments on this specification, please send an
email to the CSS Working Group's mailing list at <a
href="mailto:www-style@w3.org">www-style@w3.org</a>. (Before sending mail
for the first time, you have to subscribe at <a
href="http://lists.w3.org/Archives/Public/www-style/">http://lists.w3.org/Archives/Public/www-style/</a>.)
</details>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>This CSS3 Module describes how to insert and move content around a
document, in order to create footnotes, running headers, and other
generated content effects.
<h2 class=no-num id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-content%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-content” in the subject, preferably like this:
“[<!---->css3-content<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<!--end-status-->
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li class=no-num><a href="#status">Status of this document</a>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<li><a href="#terminology"><span class=secno>2. </span>Terminology</a>
<li><a href="#pseudo-elements"><span class=secno>3.
</span>Pseudo-elements</a>
<ul class=toc>
<li><a href="#inserting-content-into-an-element-the-be"><span
class=secno>3.1. </span>Inserting content into an element: the ‘<code
class=css>::before</code>’ and ‘<code class=css>::after</code>’
pseudo-elements</a>
<li><a href="#block-markers-the-marker-pseudo-element"><span
class=secno>3.2. </span>Block markers: The ‘<code
class=css>::marker</code>’ pseudo-element</a>
<li><a href="#line-markers-the-line-marker-pseudo-elem"><span
class=secno>3.3. </span>Line markers: The ‘<code
class=css>::line-marker</code>’ pseudo-element</a>
</ul>
<li><a href="#specifying-quotes-with-the-quotes-proper"><span
class=secno>4. </span>Specifying quotes with the <span
class=propinst-quotes>‘<code class=property>quotes</code>’</span>
property</a>
<ul class=toc>
<li><a href="#inserting-quotes-with-the-content-proper"><span
class=secno>4.1. </span>Inserting quotes with the ‘<code
class=property>content</code>’ property</a>
</ul>
<li><a href="#counters"><span class=secno>5. </span>Automatic counters and
numbering: the ‘<code class=property>counter-increment</code>’ and
‘<code class=property>counter-reset</code>’ properties</a>
<ul class=toc>
<li><a href="#nested-counters-and-scope"><span class=secno>5.1.
</span>Nested counters and scope</a>
<li><a href="#counter-styles"><span class=secno>5.2. </span>Counter
styles</a>
<li><a href="#counters-in-elements-with-display-none"><span
class=secno>5.3. </span>Counters in elements with ‘<code
class=css>display: none</code>’</a>
<li><a href="#reserved-counter-names"><span class=secno>5.4.
</span>Reserved Counter Names</a>
</ul>
<li><a href="#named-strings"><span class=secno>6. </span>Named strings</a>
<ul class=toc>
<li><a href="#atcounter-styles"><span class=secno>6.1. </span>‘<code
class=css>@counter-styles</code>’</a>
<li><a href="#page-policy"><span class=secno>6.2. </span>Determining
which counter or string-set value to use: the ‘<code
class=property>page-policy</code>’ property</a>
</ul>
<li><a href="#inserting-and-replacing-content-with-the"><span
class=secno>7. </span>Inserting and replacing content with the <span
class=propinst-content>‘<code class=property>content</code>’</span>
property</a>
<li><a href="#replacedContent"><span class=secno>8. </span>Replaced
content</a>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p>In some cases, authors may want user agents to render content that does
not come from the document tree. One familiar example of this is numbered
headings; the author does not want to mark the numbers up explicitly, he
or she wants the user agent to generate them automatically. Counters and
markers are used to achieve these effects.
<pre>
INSERT EXAMPLE HERE
</pre>
<p>Similarly, authors may want the user agent to insert the word "Figure"
before the caption of a figure, or "Chapter 7" on a line before the
seventh chapter title.
<pre>
figure > caption::before { content: "Figure: "; }
chapter:nth-child(7) > title::before { content: "Chapter 7\A"; }
</pre>
<p>The last example could also be written in a more generic way using
counters:
<pre>
chapter { counter-increment: chapter; }
chapter > title::before { content: "Chapter " counter(chapter) "\A"; }
</pre>
<p>Another common effect is replacing elements with images or other
multimedia content. Since not all user agents support all multimedia
formats, fallbacks may have to be provided.
<pre>
/* Replace &lt;logo&gt; elements with the site's logo, using a format
* supported by the UA */
logo { content: url(logo.mov), url(logo.mng), url(logo.png), none; }
/* Replace &lt;figure&gt; elements with the referenced document, or,
* failing that, with either the contents of the alt attribute or the
* contents of the element itself if there is no alt attribute */
figure[alt] { content: attr(href, url), attr(alt); }
figure:not([alt]) { content: attr(href, url), contents; }
</pre>
<p>Another effect commonly requested by authors is that of line numbering.
This module introduces the ‘<code class=css>::line-marker</code>’
pseudo-element that is attached to the front of every line box, which can
be used for this purpose.
<pre>
pre { counter-reset: line; }
pre::line-marker { counter-increment: line; content: counter(line) "."; }
</pre>
<p>This pseudo-element can also be used to simulate the indentation style
found in e-mail communication:
<pre>
blockquote { margin: 0; padding: 0 0 0 2em; } <!-- replace 'em' with 'ch' XXX -->
blockquote > blockquote { margin-left: -1em; }
blockquote::line-marker { width: 2em; text-align: left; content: ">"; }
</pre>
<p>Generated content based on the <code>cite</code> and
<code>datetime</code> attributes can create introductions or citations on
the fly as well.</p>
<!--=======================================================================-->
<h2 id=terminology><span class=secno>2. </span>Terminology</h2>
<p>This module introduces several pseudo-elements and allows them to nest
in certain predefined ways. In order to explain the relationships between
these nested pseudo-elements, three new terms have been coined.
<dl>
<dt><dfn id=originating-element>originating element</dfn>
<dd> A pseudo-element's originating element is the element to which it is
associated. e.g. the originating element of the pseudo-element matched by
‘<code class=css>::before</code>’ is the element to which it is
attached. Note that an element never has a originating element, and a
pseudo-element always has exactly one. This term is sometimes shortened
to "superior".
</dl>
<h2 id=pseudo-elements><span class=secno>3. </span>Pseudo-elements</h2>
<p>At the heart of generated content lies pseudo-elements. Pseudo-elements
create abstractions about the document tree beyond those specified by the
document language. For instance, document languages do not offer
mechanisms to access the first letter or first line of an element's
content. CSS pseudo-elements allow style sheet designers to refer to this
otherwise inaccessible information. Pseudo-elements also provide style
sheet designers a way to assign style to content that does not exist in
the source document. Pseudo elements are defined in the <a
href="#ref-SELECT" rel=biblioentry>[SELECT]<!--{{SELECT}}--></a>
specification.
<h3 id=inserting-content-into-an-element-the-be><span class=secno>3.1.
</span>Inserting content into an element: the ‘<code
class=css>::before</code>’ and ‘<code class=css>::after</code>’
pseudo-elements</h3>
<p>The ‘<code class=css>::before</code>’ and ‘<code
class=css>::after</code>’ pseudo-elements are used to insert content
immediately before and immediately after the content of an element (or
other pseudo-element). The ‘<a href="#content"><code
class=property>content</code></a>’ propety is used to specify the
content to insert.
<div class=example>
<p>For example, the following rule replaces the content of
<code>&lt;abbr&gt;</code> elements with the contents of the element's
<code>title</code> attribute:
<pre>
abbr { content: attr(title); }
</pre>
<p>The following rule inserts the string "Note: " before the content of
every P element whose "class" attribute has the value "note":
<pre>
P.note:before { content: "Note: " }
</pre>
</div>
<p>The formatting objects (e.g., boxes) generated by an element include
generated content. So, for example, changing the above style sheet to:
<pre class=example>
P.note:before { content: "Note: " }
P.note { border: solid green }
</pre>
<p>...would cause a solid green border to be rendered around the entire
paragraph, including the initial string.
<p>The ‘<code class=css>::before</code>’ and ‘<code
class=css>::after</code>’ pseudo-elements inherit any inheritable
properties from their originating element.
<p>For a ‘<code class=css>::before</code>’ or ‘<code
class=css>::after</code>’ pseudo-element to be generated, the
pseudo-element must not have its ‘<a href="#content"><code
class=property>content</code></a>’ property set to ‘<a
href="#inhibit"><code class=property>inhibit</code></a>’ or its ‘<code
class=property>display</code>’ property set to ‘<a href="#none0"><code
class=property>none</code></a>’. Note that for ‘<code
class=css>::before</code>’ and ‘<code class=css>::after</code>’
pseudo-elements, the initial value of ‘<a href="#content"><code
class=property>content</code></a>’ computes to ‘<a
href="#inhibit"><code class=property>inhibit</code></a>’.
<p>Using a ‘<code class=css>::before</code>’ pseudo-element in the
context of the anonymous table elements works exactly as if an actual
element had been introduced. For example:
<pre>
.example::before { content: "D" }
</pre>
<pre>
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt; &lt;td&gt;B&lt;/td&gt; &lt;td&gt;C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr class="example"&gt;
&lt;td&gt;E&lt;/td&gt; &lt;td&gt;F&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
</pre>
<p>An anonymous table cell box is generated around the ‘<code
class=css>::before</code>’ content in this case, resulting in a 3×2
table.
<h3 id=block-markers-the-marker-pseudo-element><span class=secno>3.2.
</span>Block markers: The ‘<code class=css>::marker</code>’
pseudo-element</h3>
<p>For a ‘<code class=css>::marker</code>’ pseudo-element to be
generated, its superior parent must have a computed ‘<code
class=property>display</code>’ value of ‘<code
class=property>list-item</code>’.
<p>For further details on the rendering model for list markers, see the
CSS3 Lists module.</p>
<!--=======================================================================-->
<h3 id=line-markers-the-line-marker-pseudo-elem><span class=secno>3.3.
</span>Line markers: The ‘<code class=css>::line-marker</code>’
pseudo-element</h3>
<p>The ‘<code class=css>::line-marker</code>’ pseudo-element is
positioned in exactly the same way as the ‘<code
class=css>::marker</code>’ pseudo-element, but appears on every line,
not just the first.
<p>Line boxes are responsible for generating ‘<code
class=css>::line-marker</code>’ pseudo-elements. For each line, one such
marker is created for every block ancestor in the current block formatting
context. [!CSS21] In addition, for the ‘<code
class=css>::line-marker</code>’ pseudo-element to be created, its ‘<a
href="#content"><code class=property>content</code></a>’ property must
have a computed value other than ‘<a href="#none0"><code
class=property>none</code></a>’ or ‘<a href="#inhibit"><code
class=property>inhibit</code></a>’.</p>
<!-- XXX need examples. Also, show overlap of nested blocks' ::marker,
::line-marker, etc. -->
<!--=======================================================================-->
<h2 id=specifying-quotes-with-the-quotes-proper><span class=secno>4.
</span><a name=quotes-specify>Specifying quotes</a> with the <a
class=propinst-quotes href="#quotes">‘<code
class=property>quotes</code>’</a> property</h2>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=quotes>quotes</dfn>
<tr>
<th>Value:
<td>foo | bar
<tr>
<th>Initial:
<td>text
<tr>
<th>Applies To:
<td>all elements
<tr>
<th>Inherited:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed value:
<td>specified value
</table>
<p>This property specifies quotation marks for any number of embedded
quotations. Values have the following meanings:
<dl>
<dt><dfn id=none>none</dfn>
<dd>The ‘<a href="#open-quote"><code
class=property>open-quote</code></a>’ and ‘<a
href="#close-quote"><code class=property>close-quote</code></a>’ values
of the ‘<a href="#content"><code class=property>content</code></a>’
property produce no quotations marks, as if they were ‘<a
href="#no-open-quote"><code class=property>no-open-quote</code></a>’
and ‘<a href="#no-close-quote"><code
class=property>no-close-quote</code></a>’ respectively.
<dt>[ &lt;string&gt; &lt;string&gt; ]+
<dd>Values for the ‘<a href="#open-quote"><code
class=property>open-quote</code></a>’ and ‘<a
href="#close-quote"><code class=property>close-quote</code></a>’ values
of the ‘<a href="#content"><code class=property>content</code></a>’
property are taken from this list of pairs of quotation marks (opening
and closing). The first (leftmost) pair represents the outermost level of
quotation, the second pair the first level of embedding, etc. The user
agent must apply the appropriate pair of quotation marks according to the
level of embedding.
</dl>
<div class=example>
<p>For example, applying the following style sheet:
<pre>
/* Specify pairs of quotes for two levels in two languages */
:lang(en) > q { quotes: '"' '"' "'" "'" }
:lang(no) > q { quotes: "+" ";" "&lt;" "&gt;" }
/* Insert quotes before and after Q element content */
q::before { content: open-quote }
q::after { content: close-quote }
</pre>
<p>to the following HTML fragment:
<pre class=html-example>
&lt;HTML lang="en"&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Quotes&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;P&gt;&lt;Q&gt;Quote me!&lt;/Q&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
<p>would allow a user agent to produce:
<pre class=ascii-art>
"Quote me!"
</pre>
<p>while this HTML fragment:
<pre class=html-example>
&lt;HTML lang="no"&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Quotes&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;P&gt;&lt;Q&gt;Trøndere gråter når &lt;Q&gt;Vinsjan på kaia&lt;/Q&gt; blir deklamert.&lt;/Q&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
<p>would produce:
<pre class=ascii-art>
+Trøndere gråter når &lt;Vinsjan på kaia&gt; blir deklamert.;
</pre>
</div>
<div class=note>
<p><em>Note.</em> While the quotation marks specified by ‘<a
href="#quotes"><code class=property>quotes</code></a>’ in the previous
examples are conveniently located on computer keyboards, high quality
typesetting would require different ISO 10646 characters. The following
informative table lists some of the ISO 10646 quotation mark characters:
<table>
<tbody>
<tr>
<th colspan=2>Codepoint
<th>Description
<tr>
<td>&#x22;
<td>U+0022
<td>QUOTATION MARK (the ASCII double quotation mark)
<tr>
<td>'
<td>U+0027
<td>APOSTROPHE (the ASCII single quotation mark)
<tr>
<td>‹
<td>U+2039
<td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK
<tr>
<td>›
<td>U+203A
<td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
<tr>
<td>«
<td>U+00AB
<td>LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
<tr>
<td>»
<td>U+00BB
<td>RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
<tr>
<td>‘
<td>U+2018
<td>LEFT SINGLE QUOTATION MARK (single high-6)
<tr>
<td>’
<td>U+2019
<td>RIGHT SINGLE QUOTATION MARK (single high-9)
<tr>
<td>“
<td>U+201C
<td>LEFT DOUBLE QUOTATION MARK (double high-6)
<tr>
<td>”
<td>U+201D
<td>RIGHT DOUBLE QUOTATION MARK (double high-9)
<tr>
<td>„
<td>U+201E
<td>DOUBLE LOW-9 QUOTATION MARK (double low-9)
</table>
</div>
<h3 id=inserting-quotes-with-the-content-proper><span class=secno>4.1.
</span>Inserting quotes with the ‘<a href="#content"><code
class=property>content</code></a>’ property</h3>
<p>Quotation marks are inserted in appropriate places in a document with
the ‘<a href="#open-quote"><code class=property>open-quote</code></a>’
and ‘<a href="#close-quote"><code
class=property>close-quote</code></a>’ values of the ‘<a
href="#content"><code class=property>content</code></a>’ property. Each
occurrence of ‘<a href="#open-quote"><code
class=property>open-quote</code></a>’ or ‘<a href="#close-quote"><code
class=property>close-quote</code></a>’ is replaced by one of the strings
from the value of ‘<a href="#quotes"><code
class=property>quotes</code></a>’, based on the depth of nesting.
<p>‘<a href="#open-quote"><code class=property>Open-quote</code></a>’
refers to the first of a pair of quotes, ‘<a href="#close-quote"><code
class=property>close-quote</code></a>’ refers to the second. Which pair
of quotes is used depends on the nesting level of quotes: the number of
occurrences of ‘<a href="#open-quote"><code
class=property>open-quote</code></a>’ in all generated text before the
current occurrence, minus the number of occurrences of ‘<a
href="#close-quote"><code class=property>close-quote</code></a>’. If the
depth is 0, the first pair is used, if the depth is 1, the second pair is
used, etc. If the depth is greater than the number of pairs, the last pair
is repeated.
<p>Note that this quoting depth is independent of the nesting of the source
document or the formatting structure.
<p>Some typographic styles require open quotation marks to be repeated
before every paragraph of a quote spanning several paragraphs, but only
the last paragraph ends with a closing quotation mark. In CSS, this can be
achieved by inserting "phantom" closing quotes. The keyword ‘<a
href="#no-close-quote"><code class=property>no-close-quote</code></a>’
decrements the quoting level, but does not insert a quotation mark.
<div class=example>
<p>The following style sheet puts opening quotation marks on every
paragraph in a BLOCKQUOTE, and inserts a single closing quote at the end:
<pre>
BLOCKQUOTE P:before { content: open-quote }
BLOCKQUOTE P:after { content: no-close-quote }
BLOCKQUOTE P.last:after { content: close-quote }
</pre>
<p>This relies on the last paragraph being marked with a class "last",
since there are no selectors that can match the last child of an element.
</div>
<p>For symmetry, there is also a <a class=index-def href="#no-open-quote"
id=x title=no-open-quote></a><a class=value-def
name=value-def-no-open-quote>‘<code
class=property>no-open-quote</code>’</a> keyword, which inserts nothing,
but increments the quotation depth by one.
<div class=note>
<p> <em>Note.</em> If a quotation is in a different language than the
surrounding text, it is customary to quote the text with the quote marks
of the language of the surrounding text, not the language of the
quotation itself.
</div>
<div class=example>
<p>For example, French inside English:
<blockquote>
<p>The device of the order of the garter is “Honi soit qui mal y
pense.”
</blockquote>
English inside French:
<blockquote>
<p>Il disait: + Il faut mettre l'action en ‹ fast forward ›.;
</blockquote>
<p>A style sheet like the following will set the ‘<a
href="#quotes"><code class=property>quotes</code></a>’ property so that
‘<a href="#open-quote"><code class=property>open-quote</code></a>’
and ‘<a href="#close-quote"><code
class=property>close-quote</code></a>’ will work correctly on all
elements. These rules are for documents that contain only English,
French, or both. One rule is needed for every additional language. Note
the use of the child combinator (">") to set quotes on elements based on
the language of the surrounding text:
<pre>
:lang(fr) > * { quotes: "+" ";" "\2039" "\203A" }
:lang(en) > * { quotes: "\201C" "\201D" "\2018" "\2019" }
</pre>
<p>The quotation marks for English are shown here in a form that most
people will be able to type. If you can type them directly, they will
look like this:
<pre>
:lang(fr) > * { quotes: "+" ";" "‹" "›" }
:lang(en) > * { quotes: "“" "”" "‘" "’" }
</pre>
</div>
<!--=======================================================================-->
<h2 id=counters><span class=secno>5. </span>Automatic counters and
numbering: the ‘<a href="#counter-increment"><code
class=property>counter-increment</code></a>’ and ‘<a
href="#counter-reset"><code class=property>counter-reset</code></a>’
properties</h2>
<p>Automatic numbering in CSS2 is controlled with two properties, ‘<a
href="#counter-increment"><code
class=property>counter-increment</code></a>’ and ‘<a
href="#counter-reset"><code class=property>counter-reset</code></a>’.
The <span class=index-def id=counters0 title=counters>counters</span>
defined by these properties are used with the ‘<code
class=css>counter()</code>’ and ‘<code class=css>counters()</code>’
functions of the the ‘<a href="#content"><code
class=property>content</code></a>’ property.
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=counter-increment>counter-increment</dfn>
<tr>
<th>Value:
<td>[ &lt;identifier&gt; &lt;integer&gt;? ]+ | none
<tr>
<th>Initial:
<td>note
<tr>
<th>Applies To:
<td>all elements, ::before, ::after, ::alternate, ::marker,
::line-marker, margin areas, @footnote areas, and @page context
<tr>
<th>Inherited:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>all
<tr>
<th>Computed value:
<td>specified value
</table>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=counter-reset>counter-reset</dfn>
<tr>
<th>Value:
<td>[ &lt;identifier&gt; &lt;integer&gt;? ]+ | none
<tr>
<th>Initial:
<td>note
<tr>
<th>Applies To:
<td>all elements, ::before, ::after, ::alternate, ::marker,
::line-marker, margin areas, @footnote areas, and @page context
<tr>
<th>Inherited:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>all
<tr>
<th>Computed value:
<td>specified value
</table>
<p>The ‘<a href="#counter-increment"><code
class=property>counter-increment</code></a>’ property accepts one or
more names of counters (identifiers), each one optionally followed by an
integer. The integer indicates by how much the counter is incremented for
every occurrence of the element. The default increment is 1. Zero and
negative integers are allowed.
<p>The ‘<a href="#counter-reset"><code
class=property>counter-reset</code></a>’ property also contains a list
of one or more names of counters, each one optionally followed by an
integer. The integer gives the value that the counter is set to on each
occurrence of the element. The default is 0.
<p>If ‘<a href="#counter-increment"><code
class=property>counter-increment</code></a>’ refers to a counter that is
not in the <a href="#counter-scope">scope (see below</a>) of any ‘<a
href="#counter-reset"><code class=property>counter-reset</code></a>’,
the counter is assumed to have been reset to 0 by the root element.
<div class=example>
<p>This example shows a way to number chapters and sections with "Chapter
1", "1.1", "1.2", etc.
<pre>
H1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* Add 1 to chapter */
counter-reset: section; /* Set section to 0 */
}
H2:before {
content: counter(chapter) "." counter(section) " ";
counter-increment: section;
}
</pre>
</div>
<p>If an element or pseudo-element resets or increments a counter and also
uses it (in its ‘<a href="#content"><code
class=property>content</code></a>’ property), the counter is used
<em>after</em> being reset or incremented.
<p>If an element or pseudo-element both resets and increments a counter,
the counter is reset first and then incremented.
<p>The ‘<a href="#counter-reset"><code
class=property>counter-reset</code></a>’ property follows the cascading
rules. Thus, due to cascading, the following style sheet:
<pre class=example>
H1 { counter-reset: section -1 }
H1 { counter-reset: imagenum 99 }
</pre>
<p>will only reset ‘<code class=property>imagenum</code>’. To reset
both counters, they have to be specified together:
<pre class=example>
H1 { counter-reset: section -1 imagenum 99 }
</pre>
<h3 id=nested-counters-and-scope><span class=secno>5.1. </span><a
name=counter-scope>Nested counters and scope</a></h3>
<p>Counters are "self-nesting", in the sense that re-using a counter in a
child element automatically creates a new instance of the counter. This is
important for situations like lists in HTML, where elements can be nested
inside themselves to arbitrary depth. It would be impossible to define
uniquely named counters for each level.
<div class=example>
<p>Thus, the following suffices to number nested list items. The result is
very similar to that of setting ‘<code
class=css>display:list-item</code>’ and ‘<code class=css>list-style:
inside</code>’ on the LI element:
<pre>
OL { counter-reset: item }
LI { display: block }
LI:before { content: counter(item) ". "; counter-increment: item }
</pre>
</div>
<p>The self-nesting is based on the principle that every element or
pseudo-element that has a ‘<a href="#counter-reset"><code
class=property>counter-reset</code></a>’ for a counter X, creates a
fresh counter X, the <dfn id=scope>scope</dfn> of which is the element or
pseudo-element, its following siblings, and all the descendants of the
element or pseudo-element and its following siblings.
<p>In the example above, an OL will create a counter, and all children of
the OL will refer to that counter.
<div class=html-example>
<p>If we denote by item[<var>n</var>] the <var>n</var><sup>th</sup>
instance of the "item" counter, and by "(" and ")" the beginning and end
of a scope, then the following HTML fragment will use the indicated
counters. (We assume the style sheet as given in the example above).
<pre>
&lt;OL&gt; &lt;!-- (set item[0] to 0 --&gt;
&lt;LI&gt;item &lt;!-- increment item[0] (= 1) --&gt;
&lt;LI&gt;item &lt;!-- increment item[0] (= 2) --&gt;
&lt;OL&gt; &lt;!-- (set item[1] to 0 --&gt;
&lt;LI&gt;item &lt;!-- increment item[1] (= 1) --&gt;