-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
1338 lines (1014 loc) · 40.4 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
<pre class='metadata'>
Title: CSS Generated Content Module Level 3
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/2016/WD-css-content-3-20160602/
Editor: Elika J. Etemad / fantasai, W3C Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Dave Cramer, Hachette Livre, dauwhe@gmail.com, w3cid 65283
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: css2 (type) <uri>, css-display-3 (value) inline
Status Text: This is a very rough draft, and is not ready for implementation.
Default Highlight: css
</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="intro">
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,
they want 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="content-property">
Inserting and replacing content with the 'content' property</h2>
<pre class='propdef'>
Name: content
Value: normal | none | [ <<content-replacement>> | <<content-list>> ] [/ <<string>> ]?
Initial: normal
Applies To: all elements, tree-abiding pseudo-elements, and page margin boxes
Inherited: no
Percentages: n/a
Computed Value: As specified below
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.</p>
The 'content' property dictates what is rendered inside an element or pseudo-element.
For elements, it has only one purpose:
specifying that the element renders as normal,
or replacing the element with an image
(and possibly some associated "alt text").
For pseudo-elements and margin boxes,
it is more powerful.
It controls whether the element renders at all,
can replace the element with an image,
or replace it with arbitrary inline content
(text and images).
<dl dfn-for="content" dfn-type=value>
<dt><dfn>normal</dfn>
<dd>
For an element, this computes to ''content/contents''.
For ''::before'' and ''::after'', this computes to ''content/none''.
<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-replacement>></dfn>
<dd id=replaced>
Equal to:
<pre class=prod><<image>></pre>
Makes the element or pseudo-element a <a href="https://www.w3.org/TR/CSS2/conform.html#replaced-element">replaced element</a>,
filled with the specified <<image>>.
Its normal contents are suppressed
and do not generate boxes,
as if they were ''display: none''.
If the <<image>> represents an <a>invalid image</a>,
then it must be treated as instead representing an image with zero intrinsic width and height,
filled with transparent black.
Issue: The above <a>invalid image</a> behavior appears to be what Chrome is doing.
Is this okay?
Is there a better behavior we can/should use?
Issue: "Zero intrinsic width and height" gives it an undefined aspect ratio,
and sizing behavior is thus... undefined.
At least, if you give it an explicit width or height,
the other dimension remains at zero in Chrome.
This might need to be explicitly defined over in the Images spec;
needs some investigation around whether browsers act this way for 0x0 SVGs and rasters.
Note: Replaced elements use different layout rules than normal elements.
(In effect, it becomes equivalent to an HTML <{img}> element.)
Note: Replaced elements do not have ''::before'' or ''::after'' pseudo-elements;
the 'content' property replaces their entire contents.
<dt><dfn type><<content-list>></dfn>
<dd>
Equal to:
<pre class=prod>
[ <<string>> | contents | <<image>> | <<quote>> | <<target>> | <<leader()>> ]+
</pre>
Replaces the element's contents with one or more anonymous inline boxes
corresponding to the specified values,
in the order specified.
Its normal contents are suppressed
and do not generate boxes,
as if they were ''display: none''.
Each value contributes an inline box to the element's contents.
For <<image>>, this is an inline anonymous replaced element;
for the others, it's an anonymous inline run of text.
If an <<image>> represents an <a>invalid image</a>,
the user agent must do one of the following:
* "Skip" the <<image>>, generating nothing for it.
* Display some indication that the image can't be displayed in place of the <<image>>,
such as a "broken image" icon.
This specification intentionally does not define which behavior a user agent must use,
but it must use one or the other consistently.
Note: If the value of <<content-list>> is a single <<image>>,
it must instead be interpreted as a <<content-replacement>>.
<dt><dfn>/ <<string>></dfn>
<dd>
Specifies the "alt text" for the element.
See [[#alt]] for details.
If omitted,
the element has no "alt text".
</dl>
Issue: Should the contents keyword be replaced with ''content()''?
<h3 id="accessibility">
Accessibility of Generated Content</h3>
Generated content should be searchable, selectable, and available to assistive technologies.
The 'content' property applies to speech
and generated content must be rendered for speech output. [[!CSS3-SPEECH]]
Issue: Start work on an AAM for CSS.
<h3 id="alt">
Alternative Text for Accessibility</h3>
Content intended for visual media sometimes needs alternative text for speech output or other non-visual mediums.
The 'content' property thus accepts alternative text
to be specified after a slash (''/'') after the last <<content-list>>.
If such alternative text is provided,
it must be used for speech output instead.
This allows, for example, purely decorative text to be elided in speech output
(by providing the empty string as alternative text),
and allows authors to provide more readable alternatives
to images, icons, or text-encoded symbols.
<!--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-values">
<<content-list>> Values and Functions</h2>
The <<content-list>> value is used in 'content'
to fill an element with one or more anonymous inline boxes,
including images, strings, the values of counters, and the text value of elements.
In this section we enumerate the possibilities.
<h3 id="strings">
String</h3>
<dl dfn-for="content, <content-list>" dfn-type=value>
<dt><dfn><<string>></dfn>
<dd>
Represents an anonymous inline box filled with the specified text.
Note: <a>White space</a> in the string is handled the same as in literal text,
and controlled by the properties in [[CSS-TEXT-3]] and elsewhere.
In particular, <a>white space</a> character can collapse,
even across multiple strings,
such as in ''content: "First " " Second";'',
which by default will render similar to <code>"First Second"</code>
(with a single visible space between the two words).
</dl>
<h3 id="content-uri">
<<image>></h3>
<dl dfn-type=value dfn-for="<content-list>">
<dt><dfn><<image>></dfn></dt>
<dd>
Represents an anonymous inline replaced element
filled with the specified <<image>>.
If the <<image>> represents an <a>invalid image</a>,
this value instead represents nothing.
(No inline content is added to the element,
as if this value were "skipped".)
</dl>
Issue: CSS2.1 explicitly allowed the UA to substitute a broken image icon
if the image was invalid.
However, no browser appears to do this.
Is this removal okay?
<h3 id="element-content">
Element Content</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>
ISSUE: Use cases for suppressing the content on the element and using it in a pseudo-element would be welcome.
Note: 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''.
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="quotes-property">
Specifying quotes with the 'quotes' property</h4>
<pre class='propdef'>
Name: quotes
Value: none | [ <<string>> <<string>> ]+
Initial: depends on user agent
Applies To: all elements
Inherited: yes
Percentages: n/a
Computed Value: specified value
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.</p>
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 <css>auto</css> 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="quote-values">
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 [[#quotes-property]] 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 [[#quotes-property]] 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.
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 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="leader-function">
The ''leader()'' function</h4>
<dl dfn-for="content, <content-list>" dfn-type=function>
<dt><dfn lt="leader()">leader( <<leader-type>> )</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( <<leader-type>> )
<dfn><<leader-type>></dfn> = 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>
Issue: Do leaders depend on the assumption that the content after the leader is right-aligned (end-aligned)?
<h4 id="leader-rules">
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:
1. The leader string must appear in full at least once.
2. The leader should be as long as possible
3. Visible characters in leaders should vertically align with each other when possible.
4. Line break characters in the leader string must be ignored.
5. White space in the leader string follows normal CSS rules.
6. A leader only appears between the start content and the end content.
7. A leader only appears on a single line, even if the before content and after content are on different lines.
8. A leader can’t be the only thing on a line.
<h4 id="leader-alignment">
Procedure for rendering leaders</h4>
1. Lay out the <var>before content</var>,
until reaching the line where the <var>before content</var> ends.
<pre>
BBBBBBBBBB
BBB
</pre>
2. 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>
3. Draw the before and after content on top of the leader.
If any part of the <var>before content</var> or <var>after content</var>
overlaps a glyph in a leader string box,
that glyph is not displayed.
<pre>
BBBBBBBBBB
BBB....AAA
</pre>
4. 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 <var>after content</var> on top,
and hide any leader strings that are not fully displayed.
<pre>
BBBBBBB
BBBBBB
......A
</pre>
<!--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:
<div class=example>
* See chapter 7
* in section 4.1
* on page 23
</div>
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.
<pre class="prod">
<dfn><<target>></dfn> = <<target-counter()>> | <<target-counters()>> | <<target-text()>>
</pre>
See sections below for details on each of these.
<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-counters( [ <<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>
Issue: A simpler syntax has been proposed by fantasai:
<a href="http://lists.w3.org/Archives/Public/www-style/2012Feb/0745.html">http://lists.w3.org/Archives/Public/www-style/2012Feb/0745.html</a>
<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">
Named strings</h3>
This section introduces <dfn lt="named string">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="string-set">
The string-set property</h4>
<pre class="propdef">
Name: string-set
Value: none | [ <<custom-ident>> <<string>>+ ]#
Initial: none
Applies to: all elements, but not pseudo-elements
Inherited: no
Percentages: N/A
Computed value: specified value
</pre>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.</p>
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 -->
If an element has <a>style containment</a>,
the 'string-set' property must have no effects on descendants of that element.
<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="string-function">
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.