-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
1116 lines (750 loc) · 36.9 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<h1>CSS Generated Content Module Level 3</h1>
<pre class='metadata'>
Status: ED
Work Status: Exploring
Shortname: css-content
Level: 3
Group: csswg
TR: https://www.w3.org/TR/css3-content/
ED: https://drafts.csswg.org/css-content/
Previous Version: https://www.w3.org/TR/2003/WD-css3-content-20030514/
Editor: Fantasai, W3C Invited Expert, http://fantasai.inkedblade.net/contact
Editor: Dave Cramer, Hachette Livre, dauwhe@gmail.com
Former Editor: Håkon Wium Lie, Opera Software, howcome@opera.com
Former Editor: Ian Hickson, Google, ian@hixie.ch
Ignored Terms: <datetime>, leader(), string(), target-counter(), target-counters(), target-text()
Abstract: This CSS3 Module describes how to insert content in a document.
Link Defaults: css21 (type) <uri>, css-display-3 (value) inline
Warning: Not Ready
</pre>
<!-- 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
!
!-->
<h2 class="no-num" id="introduction">
Introduction
</h2>
Authors sometimes 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, she or he wants the user agent to generate them automatically. Counters and markers are used to achieve these effects.
<div class="example">
<pre>
h1::before { content: counter(section) ": "; }
</pre>
</div>
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.
<div class="example">
<pre>
chapter { counter-increment: chapter; }
chapter > title::before { content: "Chapter " counter(chapter) "\A"; }
</pre>
</div>
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.
<div class="example">
<pre>
/* Replace <logo> 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 <figure> 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>
</div>
<h2 id="inserting-replacing-content">Inserting and replacing content with the 'content' property</h2>
<pre class='propdef'>
Name: content
Value: [ [ <<image>> | <<url>> ] ',' ]* [ normal | none | <<content-list>> ] [/ <<string>> ]?
Initial: normal
Applies To: all elements, ''::marker'', and page margin boxes.
Inherited: no
Percentages: n/a
Computed Value: As specified below.
Media: all
</pre>
The 'content' property dictates what is rendered inside the element or pseudo-element. It takes a comma separated list of URIs, followed by a space separated list of tokens, followed by an optional slash and string indicating alternative text. If there are multiple URIs provided, then each is tried in turn until a value which is both available and supported is found. The last value is used as a fallback if the others fail.
<dl>
<dt><dfn>normal</dfn>
<dd>For an element, this computes to ''content/contents''.
For ''::before'' and ''::after'', this computes to ''inhibit''.
<dt><dfn>none</dfn>
<dd>On elements, this inhibits the children of the element from being rendered as children of this element, as if the element was empty.
On pseudo-elements it inhibits the creation of the pseudo-element as if it had ''display: none''.
In neither case does it prevent any pseudo-elements which have this element or pseudo-element as an <a>originating element</a> from being generated.
<dt><dfn type><<content-list>></dfn>
<dd>
[ <<string>> | contents | <<uri>> | <<quote>> | ''document-url'' | <<datetime>> | <<target>> | ''leader()'' ]+
See sections below for details on each of these.
</dl>
Issue: should the contents keyword be replaced with ''content()''
<p id="replacedContent">If the computed value of the part of the 'content' property that ends up being used is a single URI, then the element or pseudo-element is a replaced element. The box model defines different rules for the layout of replaced elements than normal elements. Replaced elements do not have '::before' and '::after' pseudo-elements; the 'content' property in the case of replaced content replaces the entire contents of the element's box.
Issue: State that generated content should be searchable, selectable, and available to assistive technologies.
Generated content often needs alternative text.
If the value of the content property is a string,
this string should be used by assistive technology
unless an alternative is provided. This allows
purely decorative text to be ignored by providing
the empty string as alternative text.
Appropriate alternative text must be provided for
images inserted via the content property as well.
<!--examples from CSS-PSEUDO, redone with our new syntax-->
<div class="example">
Here the content property is an image, so the alt value is required to provide alternative text.
<pre>
.new::before {
content: url(./img/star.png) / "New!";
/* or a localized attribute from the DOM: attr("data-alt") */
}
</pre>
</div>
<div class="example">
If the pseudo-element is purely decorative and its function is covered elsewhere, setting alt to the empty string can avoid reading out the decorative element. Here the ARIA attribute will be spoken as "collapsed". Without the empty string alt value, the content would also be spoken as "Black right-pointing pointer".
<pre>
.expandable::before {
content: "\25BA" / "";
/* a.k.a. ► */
/* aria-expanded="false" already in DOM,
so this pseudo-element is decorative */
}
</pre>
</div>
<!--end copy from CSS-PSEUDO-->
<h2 id="content-functions">
Content Values and Functions</h2>
The ''content'' property can be used to add many different types of content to a document,
including images, strings, the values of counters, and the text value of elements.
In this section we enumerate the possibilities.
<h3 id="content-string">
String</h3>
<dl dfn-for="content, <content-list>" dfn-type=value>
<dt><dfn><<string>></dfn>
<dd>
The element or pseudo-element contains the specified string. Occurrences of <a>white space</a> characters in the string are handled according to the properties given in the [[CSS3TEXT]] module.
</dl>
<h3 id="content-uri">
URI</h3>
<dl dfn-type=value dfn-for=content>
<dt><<uri>></dt>
<dd>For URIs other than URIs in the last comma separated section of the value, if the URI is available and the format is supported, then the element or pseudo-element becomes a replaced element, otherwise, the next item in the comma separated list is used, if any.
</dl>
<div class="example">
<pre>
h1 { content: url(header/mng), url(header/png), none; }
</pre>
</div>
In the example above, if <code>header/mng</code> wasn't in a supported format, then <code>header/png</code> would have been used instead. In the example above, if <code>header/png</code> wasn't available either, then the <code><h1></code> element would be empty, as the last alternative is ''content/none''.
To make an element fallback on its contents, you have to explicitly give ''content/contents'' as a fallback:
<div class="example">
<pre>content: url(1), url(2), url(3), contents;</pre>
</div>
<p class="issue">What happens when no formats are supported, and the author does not explicitly indicate a fallback? Why doesn't an element fallback to ''content/contents'' unless an author explicitly says so?
If the URI is part of the last comma separated value in the list, as the second URI in the following example:
<div class="example">
<pre>h1 { content: url(welcome), "Welcome to: " url(logo); }</pre>
</div>
...then if the file is available and the format is supported, then an anonymous replaced inline element is inserted, otherwise the image is ignored (as if it hadn't been given at all).
<p class="issue">There appears to be some change from [[CSS21]] which says, "If the user agent cannot display the resource it must either leave it out as if it were not specified or display some indication that the resource cannot be displayed." Are we now saying that a user agent cannot display a missing image graphic in this situation?
When a URI is used as replaced content, it <a href="#replacedContent">affects the generation</a> of ''::before'' and ''::after'' pseudo-elements.
<h3 id="content-contents">
contents</h3>
<dl dfn-for="content, <content-list>" dfn-type=value>
<dt><dfn>contents</dfn>
<dd>The element's descendents. Since this can only be used once per element (you can't duplicate the children if, e.g., one is a plugin or form control), it is handled as follows:
: If set on the element:
:: Always honoured. Note that this is the default, since the initial value of 'content' is ''content/normal'' and ''content/normal'' computes to ''content/contents'' on an element.
: If set on one of the element's other pseudo-elements:
:: Check to see that it is not set on a "previous" pseudo-element, in the following order, depth first:
1. the element itself
2. ::before
3. ::after
Issue: Should this behave as an empty string on pseudo-elements?
If it is already used, then it evaluates to nothing (like ''content/none''). Only pseudo-elements that are actually generated are checked.
</dl>
<div class="example">
In the following case:
<pre>
foo { content: normal; } /* this is the initial value */
foo::after { content: contents; }
</pre>
...the element's 'content' property would compute to ''content/contents'' and the after pseudo element would have no contents (equivalent to ''content/none'') and thus would not appear.
<pre>
foo { content: none; }
foo::after { content: contents; }
</pre>
But in this example, the ::after pseudo-element will contain the contents of the foo element.
</div>
<p class="issue">Use cases for suppressing the content on the element and using it in a pseudo-element would be welcome.
Note that while it is useless to include ''content/contents'' twice in a single 'content' property, that is not a parse error. The second occurrence simply has no effect, as it has already been used. It is also not a parse error to use it on a marker pseudo-element, it is only during the rendering stage that it gets treated like ''content/none''.
<p class="issue">Do we need the statement about marker pseudo-elements here? Or is this legacy from the old version of the spec?
<h3 id="quotes">
Quotes</h3>
HTML has long had the <code>q</code> element, used to delimit quotations. The ''quotes'' property, in conjunction with the various *-quote values of the ''content'' property, can be used to properly style such quotations.
<h4 id="specifying-quotes">
Specifying quotes with the 'quotes' property</h4>
<pre class='propdef'>
Name: quotes
Value: [ <<string>> <<string>> ]+ | none
Initial: depends on user agent
Applies To: all elements
Inherited: yes
Percentages: n/a
Computed Value: specified value
Media: all
</pre>
<p class="issue">The previous ED had an initial value of ''text'', which was an error. [[CSS21]] has initial value of "depends on user agent". Do we use <code>auto</code> for things like this, or is it just a UA stylesheet issue?
This property specifies quotation marks for any number of embedded quotations. Values have the following meanings:
<dl dfn-type=value dfn-for=quotes>
<dt><dfn>none</dfn>
<dd>The ''open-quote'' and ''close-quote'' values of the 'content' property produce no quotations marks, as if they were ''no-open-quote'' and ''no-close-quote'' respectively.
<!--
<dt><dfn>auto</dfn>
<dd>TK
-->
<dt>[ <<string>> <<string>> ]+
<dd>Values for the ''open-quote'' and ''close-quote'' values of the 'content' 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>
<h4 id="inserting-quotes">
The *-quote values of the content property
</h4>
<pre class="prod">
<dfn><<quote>></dfn> = [open-quote | close-quote | no-open-quote | no-close-quote] )
</pre>
<dl dfn-for="content, <content-list>, <quote>" dfn-type=value>
<dt><dfn>open-quote</dfn>
<dt><dfn>close-quote</dfn>
<dd>These values are replaced by the appropriate string from the 'quotes' property, and increments (decrements) the level of nesting for quotes. See [[#specifying-quotes]] for more information.
<dt><dfn>no-open-quote</dfn>
<dt><dfn>no-close-quote</dfn>
<dd>Inserts nothing (as in ''content/none''), but increments (decrements) the level of nesting for quotes. See [[#specifying-quotes]] for more information.
</dl>
Quotation marks are inserted in appropriate places in a document with the ''open-quote'' and ''close-quote'' values of the 'content' property. Each occurrence of ''open-quote'' or ''close-quote'' is replaced by one of the strings from the value of 'quotes', based on the depth of nesting.
''open-quote'' refers to the first of a pair of quotes, ''close-quote'' refers to the second. Which pair of quotes is used depends on the nesting level of quotes: the number of occurrences of ''open-quote'' in all generated text before the current occurrence, minus the number of occurrences of ''close-quote''. 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.
Note that this quoting depth is independent of the nesting of the source document or the formatting structure.
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 ''no-close-quote'' decrements the quoting level, but does not insert a quotation mark.
<div class="example">
The following style sheet puts opening quotation marks on every paragraph in a <code>blockquote</code>, 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-child::after { content: close-quote }
</pre>
</div>
For symmetry, there is also a ''no-open-quote'' keyword, which inserts nothing, but increments the quotation depth by one.
<div class="note">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">
For example, French inside English:
<blockquote>
The device of the order of the garter is “Honi soit qui mal y pense.”
</blockquote>
English inside French:
<blockquote>
Il disait: « Il faut mettre l’action en ‹ fast
forward ›. »
</blockquote>
A style sheet like the following will set the 'quotes' property so that ''open-quote'' and ''close-quote'' 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: "\00AB\2005" "\2005\00BB" "\2039\2005" "\2005\203A" }
:lang(en) > * { quotes: "\201C" "\201D" "\2018" "\2019" }
</pre>
The quotation marks 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>
<div class="example">
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: "«" "»" "’" "’" }
/* Insert quotes before and after Q element content */
q::before { content: open-quote }
q::after { content: close-quote }
</pre>
to the following HTML fragment:
<pre class="html-example">
<html lang="en">
<head>
<title>Quotes</title>
</head>
<body>
<p><q>Quote me!</q></p>
</body>
</html>
</pre>
would allow a user agent to produce:
<pre>
"Quote me!"
</pre>
while this HTML fragment:
<pre class="html-example">
<html lang="no">
<head>
<title>Quotes</title>
</head>
<body>
<p><q>Trøndere gråter når <q>Vinsjan på kaia</q> blir deklamert.</q></p>
</body>
</html>
</pre>
would produce:
<pre>
«Trøndere gråter når ’Vinsjan på kaia’ blir deklamert.»
</pre>
</div>
<h3 id="leaders">
Leaders</h3>
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.
<h4 id="content-leader-function">
The ''leader()'' function
</h4>
<dl dfn-for="content, <content-list>" dfn-type=value>
<dt><dfn>leader()</dfn>
<dd>Inserts a leader. See the section on <a href="#leaders">leaders</a> for more information.
</dl>
<pre class="prod">
<dfn>leader()</dfn> = leader( dotted | solid | space | <<string>>);
</pre>
Three keywords are shorthand values for common strings:
<dl dfn-type=value dfn-for="leader()">
<dt><dfn>dotted</dfn>
<dd>Equivalent to ''leader(".")''
<dt><dfn>solid</dfn>
<dd>Equivalent to ''leader("_")''
<dt><dfn>space</dfn>
<dd>Equivalent to ''leader(" ")''
<dt><dfn><<string>></dfn>
<dd>
Issue: Define this.
</dl>
<div class="example">
<pre>
ol.toc a::after {
content: leader('.') target-counter(attr(href), page);
}
<h1>Table of Contents</h1>
<ol class="toc">
<li><a href="#chapter1">Loomings</a></li>
<li><a href="#chapter2">The Carpet-Bag</a></li>
<li><a href="#chapter3">The Spouter-Inn</a></li>
</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)?
<h4 id="rendering-leaders">
Rendering leaders
</h4>
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>The leader should be as long as possible
<li>Visible characters in leaders should vertically align with each other when possible.
<li>Line break characters in the leader string must be ignored.
<li>White space in the leader string follows normal CSS rules.
<li>A leader only appears between the start content and the end content.
<li>A leader only appears on a single line, even if the before content and after content are on different lines.
<li>A leader can’t be the only thing on a line.
</ol>
<h4 id="procedure-leader">
Procedure for rendering leaders
</h4>
<ol>
<li> Lay out the <var>before content</var>, until reaching the line where the <var>before content</var> ends. <pre>
BBBBBBBBBB
BBB
</pre>
<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.
<!--start alignment so leaders broken across lines work
use a hypothetical line block that extends across the whole containing block to avoid misalignment due to crazy floats -->
<pre>
BBBBBBBBBB
..........
</pre>
<li> Draw the before and after content on top of the leader. If any part of the <var>before</var> or <var>after content</var> overlaps a glyph in a leader string box, that glyph is not displayed.<pre>
BBBBBBBBBB
BBB....AAA
</pre>
<li> If one full copy of the leader string is not visible: <pre>
BBBBBBB
BBBBBBA
</pre> Insert a line break after the <var>before content</var>, draw the leader on the next line, and draw the end content on top, and hide any leader strings that are not fully displayed.<pre>
BBBBBBB
BBBBBB
......A
</pre>
</ol>
<!--put var around before and after content
define your terms -->
Issue: what to do if <var>after content</var> is wider than the line box?
Issue: Leaders don't quite work in table layouts. How can we fix this?
<figure>
<img src="images/leader.001.jpg" width="480" alt="drawing leaders"/>
<figcaption>Procedure for drawing leaders</figcaption>
</figure>
<figure>
<img src="images/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>
<h3 id="cross-references">
Cross references and the target-* functions
</h3>
Many documents contain internal references:
<ul>
<li> See chapter 7
<li> in section 4.1
<li> on page 23
</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.
<h4 id="target-counter">
The ''target-counter()'' function
</h4>
<pre class="prod">
<dfn>target-counter()</dfn> = target-counter( [ <<string>> | <<url>> ] , <<custom-ident>> [ , <<counter-style>> ]? )
</pre>
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.
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.
Issue: what should error handling be?
Issue: restrict syntactically to local references for now.
<div class="example">
HTML:
<pre>
…which will be discussed on page <a href="#chapter4_sec2"></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>
<nav>
<ol>
<li class="frontmatter"><a href="#pref_01">Preface</a></li>
<li class="frontmatter"><a href="#intr_01">Introduction</a></li>
<li class="bodymatter"><a href="#chap_01">Chapter One</a></li>
</ol>
</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>
<h4 id="target-counters">
The ''target-counters()'' function
</h4>
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( [ <<string>> | <<url>> ] , <<custom-ident>> , <<string>> [ , <<counter-style>> ]? )
</pre>
<div class="example">
<pre>
I have not found a compelling example for target-counters() yet.
</pre>
Issue: found a compelling example, in CSS specs. Do something.
</div>
<h4 id="target-text">
The ''target-text()'' function
</h4>
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-text( [ <<string>> | <<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
<div class="example">
<pre>
…which will be discussed <a href="#chapter_h1_1">later</a>.
a::after { content: ", in the chapter entitled " target-text(attr(href url)) }
</pre> Result: …which will be discussed later, in the chapter entitled Loomings.
</div>
<h3 id="named-strings-heading">
Named strings</h3>
This section introduces <dfn>named strings</dfn>, which are the textual equivalent of counters and which have a distinct namespace from counters. Named strings follow the same nesting rules as counters. The 'string-set' property accepts values similar to the 'content' property, including the extraction of the current value of counters.
Named strings are a convenient way to pull metadata out of the document for insertion into headers and footers. In HTML, for example, META elements contained in the document HEAD can set the value of named strings. In conjunction with attribute selectors, this can be a powerful mechanism:
<div class="example">
<pre>
meta[author] { string-set: author attr(author); }
head > title { string-set: title contents; }
@page:left {
@top {
text-align: left;
vertical-align: middle;
content: string(title);
}
}
@page:right {
@top {
text-align: right;
vertical-align: middle;
content: string(author);
}
}
</pre>
</div>
<!--Begin insert from GCPM3 -->
<h4 id="setting-named-strings-the-string-set-pro">
The string-set property
</h4>
<pre class="propdef">
Name: string-set
Value: [ <<custom-ident>> <<string>>+ ]# | 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 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.
<dl dfn-type=value dfn-for=string-set>
<dt><dfn>none</dfn>
<dd>
The element does not set any named strings.
<dt><code>[ <<custom-ident>> <<string>>+ ]#</code>
<dd>
The element establishes one or more named strings,
corresponding to each comma-separated entry in the list.
For each entry, the <<custom-ident>> gives the name of the named string.
It's followed by one or more <<string>> values,
which are concatenated together to form the value of the named string.
</dl>
<!--end of insert from GCPM3 -->
<div class="example">
The following example captures the contents of H1 elements, which represent chapter names in this hypothetical document.
<pre>H1 { string-set: chapter contents; }</pre>
When an H1 element is encountered, the ''chapter'' string is set to the element's textual contents, and the previous value of ''chapter'', if any, is overwritten.
</div>
<h4 id="using-named-strings">The ''string()'' function</h4>
<pre class="prod">
<dfn>string()</dfn> = string( <<custom-ident>> , [ first | start | last | first-except ]? )
</pre>
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 multiple elements defining the string can appear) an optional second argument indicates which value of the named string should be used.
The second argument of the ''string()'' function is one of the following keywords:
<dl dfn-type="value" dfn-for="string()">
<dt><dfn>first</dfn>
<dd>The value of the first assignment on the page is used. If there is no assignment on the page, the <a>entry value</a> is used. If no second argument is provided, this is the default value.
<dt><dfn>start</dfn>
<dd>If the element is the first element on the page, the value of the first assignment is used. Otherwise the <a>entry value</a> is used. The <a>entry value</a> may be empty if the <a>named string</a> hasn’t yet appeared.
<dt><dfn>last</dfn>
<dd>The <a>exit value</a> of the named string is used.
<dt><dfn>first-except</dfn>
<dd>This is identical to ''string()/first'', except that the empty string is used on the page where the value is assigned.
Issue: we may need to kill the entire content string. Is this necessary?
</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.
<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="images/using-strings-1.jpg" width="480" alt=""/>
<figcaption>The ''string-set/start'' value is empty, as the string had not yet been set at the start of the page.</figcaption>
</figure>
<figure>
<img src="images/using-strings-2.jpg" width="480" alt=""/>
<figcaption>Since the page starts with an h2, the ''string-set/start'' value is the value of that head.</figcaption>
</figure>
<figure>
<img src="images/using-strings-3.jpg" width="480" alt=""/>
<figcaption>Since there’s not an h2 at the top of this page, the ''string-set/start'' value is the <a>exit value</a> of the previous page.</figcaption>
</figure>
</div>
<h4 id="content-function-header">The ''content()'' function</h4>
<pre class="prod">
<dfn>content()</dfn> = content( [text | before | after | first-letter | marker ]? )
</pre>
<dl dfn-type="value" dfn-for="content()">
<dt><dfn>text</dfn>
<dd>The string value of the element.
If no value is specified in ''content()'',
it acts as if ''content()/text'' were specified.
<dt><dfn>before</dfn>
<dd>The string value of the ''::before'' pseudo-element.
<dt><dfn>after</dfn>
<dd>The string value of the ''::after'' pseudo-element.
<dt><dfn>first-letter</dfn>
<dd>The first letter of the element, as defined for the ''::first-letter'' pseudo-element
<dt><dfn>marker</dfn>
<dd>The string value of the ''::marker'' pseudo-element.
</dl>
<div class="example">
HTML:
<pre>
<h1>Loomings</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>
<section title="Loomings">
</pre>
CSS:
<pre>
section { string-set: header attr(title) }
</pre>
The value of the “header” string will be “Loomings”.
</div>
<h2 id="counters">
Automatic counters and numbering: the 'counter-increment' and 'counter-reset' properties (moved)</h2>
<p class="issue">Now described in [[CSS3LIST]]
<p class="issue">Should this move back to CSS Content?
<h2 id="css-bookmarks">
Bookmarks
</h2>
Some document formats, most notably PDF, allow the use of <dfn>bookmarks</dfn> as an aid to navigation. Bookmarks provide a hierarchy of links to document elements, as well as text to label the links. A bookmark has three properties: 'bookmark-level', 'bookmark-label', and 'bookmark-state'.
A bookmark references that element in the document. When a user activates a bookmark, the user agent must bring that reference point to the user's attention, exactly as if navigating to that element by fragment URL. <span class="note">This will also trigger matching the '':target'' pseudo-class.</span>
<h3 id="bookmark-level">
bookmark-level
</h3>
The 'bookmark-level' property determines if a bookmark is created, and at what level. If this property is absent, or has value ''bookmark-level/none'', no bookmark should be generated, regardless of the values of 'bookmark-label' or 'bookmark-state'.
<pre class="propdef">
Name: bookmark-level
Value: none | <integer>
Initial: none
Applies to: all elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
</pre>
<dl dfn-type="value" dfn-for="bookmark-level">
<dt><integer>
<dd>defines the level of the bookmark, with the highest level being 1 (negative and zero values are invalid).
<dt>none