Skip to content

Commit dfac6c5

Browse files
authored
[css-lists] Define reversed counters with automatic initial value (#6096)
1 parent f6b610a commit dfac6c5

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

css-lists-3/Overview.bs

+36-17
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ Automatic Numbering With Counters</h2>
744744
which are inherited through the document tree in a way similar to inherited property values.
745745
[=Counters=] have a <dfn export for="CSS counter">name</dfn> and <dfn export for="CSS counter">creator</dfn>,
746746
which identify the counter,
747-
and an integer <dfn export for="CSS counter">value</dfn>.
747+
a boolean <dfn export for="CSS counter">reversed</dfn> (false by default),
748+
and an integer <dfn export for="CSS counter">value</dfn> (optional when the counter is <a>reversed</a>).
748749
They are created and manipulated with
749750
the <dfn export>counter properties</dfn> 'counter-increment', 'counter-set' and 'counter-reset',
750751
and used with the ''counter()'' and ''counters()'' [=functional notations=].
@@ -755,6 +756,13 @@ Automatic Numbering With Counters</h2>
755756
A <<counter-name>> name cannot match the keyword ''counter-reset/none'';
756757
such an identifier is [=invalid=] as a <<counter-name>>.
757758

759+
A <a>reversed</a> counter is created with the ''reversed()'' [=functional notation=],
760+
which is defined as follows:
761+
762+
<pre>
763+
<dfn><<reversed-counter-name>></dfn> = reversed( <<counter-name>> )
764+
</pre>
765+
758766
Resolving [=counter=] values on a given element is a multi-step process:
759767

760768
1. Existing counters are [=inherit counters|inherited=] from previous elements.
@@ -774,12 +782,12 @@ Creating Counters: the 'counter-reset' property</h3>
774782

775783
<pre class="propdef">
776784
Name: counter-reset
777-
Value: [ <<counter-name>> <<integer>>? ]+ | none
785+
Value: [ <<counter-name>> <<integer>>? | <<reversed-counter-name>> <<integer>>? ]+ | none
778786
Initial: none
779787
Applies to: all elements
780788
Inherited: no
781789
Percentages: n/a
782-
Computed value: the keyword ''counter-reset/none'' or a list, each item an identifier paired with an integer
790+
Computed value: the keyword ''counter-reset/none'' or a list, each item an identifier or a ''reversed()'' function paired with an integer
783791
Animation type: by computed value type
784792
</pre>
785793

@@ -799,6 +807,12 @@ Creating Counters: the 'counter-reset' property</h3>
799807
[=Instantiates=] a counter of the given <<counter-name>>
800808
with a starting value of the given <<integer>>,
801809
defaulting to ''0''.
810+
811+
<dt><dfn><<reversed-counter-name>> <<integer>>?</dfn>
812+
<dd>
813+
[=Instantiates=] a <a>reversed</a> counter of the given <<counter-name>>
814+
with a starting value of the given <<integer>>,
815+
or no starting value if not given.
802816
</dl>
803817

804818
<div class='example' highlight=css>
@@ -993,7 +1007,8 @@ Creating and Inheriting Counters</h3>
9931007
whose values are each a [=tuple=] of:
9941008
a [=string=] (representing a counter’s [=name=]),
9951009
an element (representing the counter’s [=creator=]),
996-
and an integer (representing the counter’s [=value=]).
1010+
a boolean (representing whether the counter is [=reversed=]),
1011+
and optionally an integer (representing the counter’s [=value=]).
9971012
The latest [=counter=] of a given name in that set
9981013
represents the <dfn>innermost</dfn> counter of that name.
9991014

@@ -1106,8 +1121,9 @@ Instantiating Counters</h4>
11061121
see [[#nested-counters]].)
11071122
To <dfn lt="instantiate counter" local-lt="instantiate">instantiate a counter</dfn>
11081123
of a given |name|
1109-
on an |element|
1110-
with a starting |value|:
1124+
on an |element|,
1125+
optionally |reversed|,
1126+
with an optional starting |value|:
11111127

11121128
1. Let |counters| be |element|’s [=CSS counters set=].
11131129

@@ -1120,9 +1136,16 @@ Instantiating Counters</h4>
11201136
3. [=set/Append=] a new [=counter=] to |counters|
11211137
with name |name|,
11221138
originating element |element|,
1123-
and initial value |value|
1139+
reversed being |reversed|,
1140+
and initial value |value| (if given)
11241141
</div>
11251142

1143+
When a [=counter=] is [=instantiated=] without an initial value,
1144+
the user agent must dynamically calculate the initial value at layout-time
1145+
to be the number of elements and pseudo-elements that [=instantiate=] the same counter in the same [=scope=], plus 1.
1146+
1147+
Note: Only [=reversed=] counters can be instantiated without an initial value.
1148+
11261149
<h3 id='counters-without-boxes'>
11271150
Counters in elements that do not generate boxes</h3>
11281151

@@ -1171,8 +1194,10 @@ The Implicit ''list-item'' Counter</h3>
11711194
unless the 'counter-increment' property explicitly specifies
11721195
a different increment for the ''list-item'' counter,
11731196
it must be incremented by 1 on every [=list item=],
1197+
or if the counter is <a>reversed</a>,
1198+
it must be incremented by -1 on every [=list item=] instead,
11741199
at the same time that <a>counters</a> are normally incremented
1175-
(exactly as if the [=list item=] had ''list-item 1'' appended to their 'counter-increment' value,
1200+
(exactly as if the [=list item=] had ''list-item 1'' or ''list-item -1'' appended to their 'counter-increment' value,
11761201
including side-effects such as possibly [=instantiating=] a new [=counter=], etc).
11771202
This does not affect the [=specified value|specified=] or [=computed values=]
11781203
of 'counter-increment'.
@@ -1487,9 +1512,6 @@ Appendix A: Sample Style Sheet For HTML</h2>
14871512
this sample style sheet is provided to illustrate the CSS features
14881513
using familiar markup conventions.</em>
14891514

1490-
ISSUE: Discussion of how to support <code>ol[reversed]</code> list numbering in CSS is ongoing.
1491-
See, e.g. <a href="https://github.com/w3c/csswg-drafts/issues/4181">Issue 4181</a>.
1492-
14931515
<pre>
14941516
/* Set up list items */
14951517
li {
@@ -1525,16 +1547,13 @@ Appendix A: Sample Style Sheet For HTML</h2>
15251547
counter-set: list-item attr(value integer, 1);
15261548
}
15271549

1528-
<!--
15291550
/* Handling reversed lists */
15301551
ol[reversed] {
1531-
counter-reset: list-item calc(attr(start integer, **magic**) + 1);
1532-
/* Where **magic** is the number of child &lt;li> elements. */
1552+
counter-reset: reversed(list-item);
15331553
}
1534-
ol[reversed] > li {
1535-
/* HTML implies 'counter-increment: list-item -1' */
1554+
ol[reversed][start] {
1555+
counter-reset: reversed(list-item) calc(attr(start integer) + 1);
15361556
}
1537-
-->
15381557

15391558
/* Box Model Rules */
15401559
ol, ul {

0 commit comments

Comments
 (0)