-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.html
1118 lines (945 loc) · 78.9 KB
/
Overview.html
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
<!DOCTYPE html><html lang=en><head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Pseudo-Elements Module Level 4</title>
<link href=../default.css rel=stylesheet type=text/css>
<link href=../csslogo.ico rel="shortcut icon" type=image/x-icon>
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
</head>
<body class=h-entry>
<div class=head>
<p data-fill-with=logo><a class=logo href=http://www.w3.org/>
<img alt=W3C height=48 src=https://www.w3.org/Icons/w3c_home width=72>
</a>
</p>
<h1 class="p-name no-ref" id=title>CSS Pseudo-Elements Module Level 4</h1>
<h2 class="no-num no-toc no-ref heading settled" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20141026>26 October 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl>
<dt>This version:
<dd><a class=u-url href=http://dev.w3.org/csswg/css-pseudo-4/>http://dev.w3.org/csswg/css-pseudo-4/</a>
<dt>Latest version:
<dd><a href=http://www.w3.org/TR/css-pseudo-4/>http://www.w3.org/TR/css-pseudo-4/</a>
<dt>Feedback:
<dd><a href="mailto:www-style@w3.org?subject=%5Bcss-pseudo%5D%20feedback">www-style@w3.org</a>
with subject line
“<kbd>[css-pseudo] <var>… message topic …</var></kbd>”(<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)
<dt>Editors:
<dd><dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://fantasai.inkedblade.net/contact>fantasai</a> (<span class="p-org org">Invited Expert</span>)
<dd><dd class="p-author h-card vcard"><a class="p-name fn u-email email" href=mailto:stearns@adobe.com>Alan Stearns</a> (<span class="p-org org">Adobe Systems Inc.</span>)
</dl>
</div>
<div data-fill-with=warning></div>
<p class=copyright data-fill-with=copyright><a href=http://www.w3.org/Consortium/Legal/ipr-notice#Copyright>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>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id=abstract><span class=content>Abstract</span></h2>
<div class=p-summary data-fill-with=abstract><p>This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.</p>
<a href=http://www.w3.org/TR/CSS/>CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</div>
<h2 class="no-num no-toc no-ref heading settled" id=status><span class=content>Status of this document</span></h2>
<div data-fill-with=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=%5Bcss-pseudo%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 “css-pseudo” in the subject,
preferably like this:
“[css-pseudo] <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>.</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc>
<li><a href=#intro><span class=secno>1</span> Introduction</a>
<li><a href=#typographic-pseudos><span class=secno>2</span> Typographic Pseudo-elements</a>
<ul class=toc>
<li><a href=#first-line-pseudo><span class=secno>2.1</span> The ::first-line pseudo-element</a>
<ul class=toc>
<li><a href=#first-text-line><span class=secno>2.1.1</span> Finding the First Formatted Line</a>
<li><a href=#first-line-styling><span class=secno>2.1.2</span> Styling the First Line Pseudo-element</a>
<li><a href=#first-line-inheritance><span class=secno>2.1.3</span> Inheritance and the <span class=css data-link-type=maybe title=::first-line>::first-line</span> Pseudo-element</a></ul>
<li><a href=#first-letter-pseudo><span class=secno>2.2</span> The ::first-letter pseudo-element</a>
<ul class=toc>
<li><a href=#application-in-css><span class=secno>2.2.1</span> Finding the First Letter</a>
<li><a href=#first-letter-styling><span class=secno>2.2.2</span> Styling the <span class=css>::first-letter</span> Pseudo-element</a></ul></ul>
<li><a href=#highlight-pseudos><span class=secno>3</span> Highlight Range Pseudo-element: <span class=css data-link-type=maybe title=::selection>::selection</span></a>
<ul class=toc>
<li><a href=#highlight-styling><span class=secno>3.1</span> Styling Highlighted Ranges</a></ul>
<li><a href=#generated-content><span class=secno>4</span> Generated Content Pseudo-elements: <span class=css data-link-type=maybe title=::before>::before</span> and <span class=css data-link-type=maybe title=::after>::after</span></a>
<li><a href=#interactions><span class=secno>5</span> Overlapping Pseudo-element Interactions</a>
<li><a href=#cssom><span class=secno>6</span> Additions to the CSS Object Model</a>
<ul class=toc>
<li><a href=#CSSPseudoElement-interface><span class=secno>6.1</span> Interface CSSPseudoElement</a>
<li><a href=#CSSPseudoElementList-interface><span class=secno>6.2</span> Interface CSSPseudoElementList</a>
<li><a href=#window-interface><span class=secno>6.3</span> Addition to the <code>window</code> interface</a></ul>
<li><a href=#acknowledgements><span class=secno></span> Acknowledgements</a>
<li><a href=#conformance><span class=secno></span> Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span> Document conventions</a>
<li><a href=#conformance-classes><span class=secno></span> Conformance classes</a>
<li><a href=#partial><span class=secno></span> Partial implementations</a>
<li><a href=#experimental><span class=secno></span> Experimental implementations</a>
<li><a href=#testing><span class=secno></span> Non-experimental implementations</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a>
<li><a href=#property-index><span class=secno></span> Property index</a>
<li><a href=#issues-index><span class=secno></span> Issues Index</a></ul></div>
<h2 class="heading settled" data-level=1 id=intro><span class=secno>1 </span><span class=content>Introduction</span><a class=self-link href=#intro></a></h2>
<p><em>This section is informative.</em></p>
<p><a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#pseudo-element title=Pseudo-elements>Pseudo-elements</a> represent abstract elements of the document
beyond those elements explicitly created by the document language.
Since they are not restricted to fitting into the document tree,
the can be used the select and style portions of the document
that do not necessarily map to the document’s tree structure.
For instance, the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element can
select content on the first formatted line of an element
<em>after</em> text wrapping,
allowing just that line to be styled differently
from the rest of the paragraph.</p>
<p>Each pseudo-element is associated with an <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>
and has syntax of the form <span class=css>::name-of-pseudo</span>.
This module defines the pseudo-elements that exist in CSS
and how they can be styled.
For more information on pseudo-elements in general,
and on their syntax and interaction with other <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#selector title=selectors>selectors</a>,
see <a data-biblio-type=normative data-link-type=biblio href=#biblio-selectors4 title=biblio-SELECTORS4>[SELECTORS4]</a>.</p>
<h2 class="heading settled" data-level=2 id=typographic-pseudos><span class=secno>2 </span><span class=content>
Typographic Pseudo-elements</span><a class=self-link href=#typographic-pseudos></a></h2>
<h3 class="heading settled" data-level=2.1 id=first-line-pseudo><span class=secno>2.1 </span><span class=content>
The ::first-line pseudo-element</span><a class=self-link href=#first-line-pseudo></a></h3>
<p>The <dfn class=css data-dfn-type=selector data-export="" id=selectordef-first-line>::first-line<a class=self-link href=#selectordef-first-line></a></dfn> pseudo-element describes the contents of
the <a data-link-type=dfn href=#first-formatted-line title="first formatted line">first formatted line</a> of its <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>.</p>
<div class=example>
The rule below means
“change the letters of the first line of every <code>p</code> element to uppercase”:
<pre>p::first-line { text-transform: uppercase }</pre>
<p>The selector <span class=css>p::first-line</span>
does not match any real document element.
It does match a pseudo-element that conforming user agents
will insert at the beginning of every <code>p</code> element.</p>
</div>
<p class=note>Note: Note that the length of the first line depends on a number of factors,
including the width of the page, the font size, etc.</p>
<div class=example>
For example, given an ordinary HTML <a data-biblio-type=informative data-link-type=biblio href=#biblio-html5 title=biblio-HTML5>[HTML5]</a> paragraph such as:
<pre><P>This is a somewhat long HTML
paragraph that will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
<p>The lines might be broken as follows:</p>
<pre>THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
will be broken into several lines. The first
line will be identified by a fictional tag
sequence. The other lines will be treated as
ordinary lines in the paragraph.
</pre>
<p>This paragraph might be “rewritten” by user agents
to include a <dfn data-dfn-type=dfn data-noexport="" id=fictional-tag-sequence>fictional tag sequence<a class=self-link href=#fictional-tag-sequence></a></dfn> to represent <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a>.
This <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> helps to show how properties are inherited.</p>
<pre><P><b><P::first-line></b> This is a somewhat long HTML
paragraph that <b></P::first-line></b> will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
</div>
<p>If a pseudo-element breaks up a real element,
the desired effect can often be described by a <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a>
that closes and then re-opens the element.</p>
<div class=example>
Thus, if we mark up the previous paragraph with a <code>span</code>
element encompassing the first sentence:
<pre><P><b><SPAN class="test"></b> This is a somewhat long HTML
paragraph that will be broken into several
lines.<b></SPAN></b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
<p>the user agent could simulate start and end tags for <code>span</code>
when inserting the <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> for <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a>
to get the correct inheritance behavior.</p>
<pre><P><P::first-line><b><SPAN class="test"></b> This is a somewhat long HTML
paragraph that will <b></SPAN></b></P::first-line><b><SPAN class="test"></b> be broken into several
lines.<b></SPAN></b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
</pre>
</div>
<h4 class="heading settled" data-level=2.1.1 id=first-text-line><span class=secno>2.1.1 </span><span class=content>
Finding the First Formatted Line</span><a class=self-link href=#first-text-line></a></h4>
<p>In CSS, the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element
can only have an effect when attached to a <a data-link-type=dfn href=http://dev.w3.org/csswg/css-display-3/#block-container title="block container">block container</a>.
The <dfn data-dfn-type=dfn data-noexport="" id=first-formatted-line>first formatted line<a class=self-link href=#first-formatted-line></a></dfn> of an element
must occur inside a block-level descendant in the same flow
(i.e., a block-level descendant that is not out-of-flow due to floating or positioning).</p>
<div class=example>
For example, the first line of the <code>DIV</code> in <code><DIV><P>This line...</P></DIV></code>
is the first line of the <code>P</code>
(assuming that both <code>P</code> and <code>DIV</code> are blocks).
</div>
<p>The first line of a table-cell or inline-block
cannot be the first formatted line of an ancestor element.
Thus, in <code><DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV></code>
the first formatted line of the <code>DIV</code> is not the line "Hello".</p>
<p class=note>Note: Note that the first line of the <code>p</code> in this fragment:
<code><p><br>First...</code>
doesn’t contain any letters (assuming the default style for <code>br</code>).
The word "First" is not on the first formatted line.</p>
<p>A user agent must act as if the fictional start tags of a <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element
were nested just inside the innermost enclosing block-level element.</p>
<div class=example>
For example, the <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> for
<pre><DIV>
<P>First paragraph</P>
<P>Second paragraph</P>
</DIV>
</pre>
<p>is
<pre><DIV>
<P><DIV::first-line><P::first-line>First paragraph</P::first-line></DIV::first-line></P>
<P><P::first-line>Second paragraph</P::first-line></P>
</DIV>
</pre><p></p>
</div>
<h4 class="heading settled" data-level=2.1.2 id=first-line-styling><span class=secno>2.1.2 </span><span class=content>
Styling the First Line Pseudo-element</span><a class=self-link href=#first-line-styling></a></h4>
<p>The <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element’s generated box
behaves similar to that of an inline-level element, but with certain restrictions.
The following CSS properties apply to a <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element:
<ul>
<li>all font properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3-fonts title=biblio-CSS3-FONTS>[CSS3-FONTS]</a>)
<li>the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a> and <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#opacity title=opacity>opacity</a> properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3color title=biblio-CSS3COLOR>[CSS3COLOR]</a>)
<li>all background properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3bg title=biblio-CSS3BG>[CSS3BG]</a>)
<li>any typesetting properties that apply to inline elements (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3text title=biblio-CSS3TEXT>[CSS3TEXT]</a>)
<li>all text decoration properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3-text-decor title=biblio-CSS3-TEXT-DECOR>[CSS3-TEXT-DECOR]</a>)
<li>any inline layout properties that apply to inline elements (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3line title=biblio-CSS3LINE>[CSS3LINE]</a>)
<li>any other properties defined to apply to <span class=css>::first-letter</span>
by their respective specifications
</ul>
User agents may apply other properties as well.<p></p>
<h4 class="heading settled" data-level=2.1.3 id=first-line-inheritance><span class=secno>2.1.3 </span><span class=content>
Inheritance and the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> Pseudo-element</span><a class=self-link href=#first-line-inheritance></a></h4>
<p>During CSS inheritance, the portion of a child element that occurs on the first line
only inherits properties applicable to the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element
from the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> pseudo-element.
For all other properties inheritence is
from the non-pseudo-element parent of the first line pseudo element.
(The portion of a child element that does not occur on the first line
always inherits from the parent of that child.)</p>
<h3 class="heading settled" data-level=2.2 id=first-letter-pseudo><span class=secno>2.2 </span><span class=content>
The ::first-letter pseudo-element</span><a class=self-link href=#first-letter-pseudo></a></h3>
<p>The <span class=css>::first-letter</span> pseudo-element represents
the first <i data-link-type=dfn title="typographic letter unit">typographic letter unit</i> <a data-biblio-type=normative data-link-type=biblio href=#biblio-css3text title=biblio-CSS3TEXT>[CSS3TEXT]</a>
on the <a data-link-type=dfn href=#first-formatted-line title="first formatted line">first formatted line</a> of its <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>,
if it is not preceded by any other content
(such as images or inline tables) on its line.
The <span class=css>::first-letter</span> pseudo-element can be used
to create “initial caps” and “drop caps”,
which are common typographic effects.</p>
<div class=example>
For example, the following rule creates a 2-line drop-letter
on every paragraph following a level-2 header,
using the <a class=property data-link-type=propdesc title=initial-letter>initial-letter</a> property defined in <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3line title=biblio-CSS3LINE>[CSS3LINE]</a>:
<pre>h2 + p::first-letter { initial-letter: 2; }
</pre>
</div>
<p>Punctuation (i.e, characters that belong to the Punctuation (<code>P*</code>) <i data-link-type=dfn title="Unicode general category">Unicode general category</i> <a data-biblio-type=normative data-link-type=biblio href=#biblio-uax44 title=biblio-UAX44>[UAX44]</a>)
that precedes or follows the first <i data-link-type=dfn title="typographic letter unit">typographic letter unit</i> must also be included
in the <span class=css>::first-letter</span> pseudo-element.</p>
<div class=figure>
<img alt="Quotes that precede the first letter should be included." src=http://www.w3.org/TR/selectors/first-letter2.png>
</div>
<p>As explained in <a data-biblio-type=normative data-link-type=biblio href=#biblio-css3text title=biblio-CSS3TEXT>[CSS3TEXT]</a>,
a <i data-link-type=dfn title="typographic letter unit">typographic letter unit</i> can include more than one Unicode codepoint.
For example, combining characters must be kept with their base character.
Also, languages may have additional rules
about how to treat certain letter combinations.
In Dutch, for example, if the letter combination "ij" appears at the beginning of an element,
both letters should be considered within the <span class=css>::first-letter</span> pseudo-element. <a data-biblio-type=informative data-link-type=biblio href=#biblio-uax29 title=biblio-UAX29>[UAX29]</a>
The UA should tailor its definition of <i data-link-type=dfn title="typographic letter unit">typographic letter unit</i>
to reflect the first-letter traditions of the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>’s content language.
Issue: This is actually a problem in cases where the originating element is an ancestor
with a different content. What <em>should</em> we say here?</p>
<p class=note>Note: Note that the first <i data-link-type=dfn title="typographic letter unit">typographic letter unit</i> may in fact
be a digit, e.g., the “6” in “67 million dollars is a lot of money.”</p>
<p>If the characters that would form the <span class=css>::first-letter</span>
are not in the same element, such as "‘<code class=css>T" in <code><p>'<em>T...</code>,
the user agent may create a <span class=css>::first-letter</span> pseudo-element
from one of the elements, both elements, or simply not create a pseudo-element.</code>
Additionally, if the first letter(s) of the block
are not at the start of the line (for example due to bidirectional reordering),
then the user agent need not create the pseudo-element(s).</p>
<p>The <span class=css>::first-letter</span> pseudo-element is contained within any <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a>
pseudo-elements, and thus inherits from <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a>.</p>
<h4 class="heading settled" data-level=2.2.1 id=application-in-css><span class=secno>2.2.1 </span><span class=content>
Finding the First Letter</span><a class=self-link href=#application-in-css></a></h4>
<p>The first letter must occur on the <a data-link-type=dfn href=#first-formatted-line title="first formatted line">first formatted line</a>.
For example, in this HTML fragment: <code><p><br>First...</code>
the first line doesn’t contain any letters
and <span class=css>::first-letter</span> doesn’t match anything.
In particular, it does not match the “F” of “First”.</p>
<p>In CSS, the <span class=css>::first-letter</span> pseudo-element
only applies to block containers.
<span class=note>A future version of this specification
may allow this pseudo-element to apply to more display types.</span>
The <span class=css>::first-letter</span> pseudo-element can be used
with all such elements that contain text,
or that have a descendant in the same flow that contains text.
A user agent should act as if the fictional start tag
of the ::first-letter pseudo-element
is just before the first text of the element,
even if that first text is in a descendant.</p>
<div class=example>
Example:
The <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> for this HTML fragment:
<pre><div>
<p>The first text.
</pre>
<p>is:
<pre><div>
<p><div::first-letter><p::first-letter>T</...></...>he first text.
</pre><p></p>
</div>
<p>In CSS the first letter of a table-cell or inline-block
cannot be the first letter of an ancestor element.
Thus, in <code><DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV></code>
the first letter of the <code>DIV</code> is not the letter "H".
In fact, the <code>DIV</code> doesn’t have a first letter.
If an element is a list item (<a class=css data-link-type=propdesc href=http://dev.w3.org/csswg/css2/visuren.html#propdef-display title=display>display: list-item</a>),
the <span class=css>::first-letter</span> applies
to the first letter in the principal box <em>after</em> the marker.
User-Agents may ignore <span class=css>::first-letter</span>
on list items with <a class=css data-link-type=propdesc href=http://dev.w3.org/csswg/css-lists-3/#propdef-list-style-position title=list-style-position>list-style-position: inside</a>.
If an element has <a class=css data-link-type=maybe href=#selectordef-before title=::before>::before</a> or <a class=css data-link-type=maybe href=#selectordef-after title=::after>::after</a> content,
the <span class=css>::first-letter</span> applies to the first letter of the
element <em>including</em> that content.</p>
<div class=example>
Example:
After the rule <span class=css>p::before {content: "Note: "}</span>, the
selector <span class=css>p::first-letter</span> matches the "N" of "Note".
</div>
<h4 class="heading settled" data-level=2.2.2 id=first-letter-styling><span class=secno>2.2.2 </span><span class=content>
Styling the <span class=css>::first-letter</span> Pseudo-element</span><a class=self-link href=#first-letter-styling></a></h4>
<p>In CSS a ::first-letter pseudo-element is similar to an inline-level element
if its <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css2/visuren.html#propdef-float title=float>float</a> property is <span class=css>none</span>;
otherwise, it is similar to a floated element.
The following properties that apply to <span class=css>::first-letter</span> pseudo-elements:</p>
<ul>
<li>all font properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3-fonts title=biblio-CSS3-FONTS>[CSS3-FONTS]</a>)
<li>the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a> and <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#opacity title=opacity>opacity</a> properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3color title=biblio-CSS3COLOR>[CSS3COLOR]</a>)
<li>all background properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3bg title=biblio-CSS3BG>[CSS3BG]</a>)
<li>any typesetting properties that apply to inline elements (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3text title=biblio-CSS3TEXT>[CSS3TEXT]</a>)
<li>all text decoration properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3-text-decor title=biblio-CSS3-TEXT-DECOR>[CSS3-TEXT-DECOR]</a>)
<li>any inline layout properties that apply to inline elements (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3line title=biblio-CSS3LINE>[CSS3LINE]</a>)
<li>margin and padding properties (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css21 title=biblio-CSS21>[CSS21]</a>)
<li>border properties and <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#box-shadow title=box-shadow>box-shadow</a> (see <a data-biblio-type=informative data-link-type=biblio href=#biblio-css3bg title=biblio-CSS3BG>[CSS3BG]</a>)
<li>any other properties defined to apply to <span class=css>::first-letter</span>
by their respective specifications
</ul>
<p>User agents may apply other properties as well.</p>
<p>To allow User-Agents to render a typographically correct drop cap or initial cap,
the User-Agent may choose a line-height, width and height
based on the shape of the letter, unlike for normal elements.</p>
<div class=example>
Example:
This CSS and HTML example shows a possible rendering of an initial cap.
Note that the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css2/visudet.html#propdef-line-height title=line-height>line-height</a> that is inherited
by the <span class=css>::first-letter</span> pseudo-element is 1.1,
but the User-Agent in this example has computed the height
of the first letter box differently,
so that it doesn’t cause any unnecessary space between the first two lines.
Also note that the fictional start tag of the first letter
is inside the <span>span</span>,
and thus the font weight of the first letter is normal,
not bold as the <span>span</span>:
<pre>p { line-height: 1.1 }
p::first-letter { font-size: 3em; font-weight: normal }
span { font-weight: bold }
...
<p><span>Het hemelsche</span> gerecht heeft zich ten lange lesten<br>
Erbarremt over my en mijn benaeuwde vesten<br>
En arme burgery, en op mijn volcx gebed<br>
En dagelix geschrey de bange stad ontzet.
</pre>
<div class=figure>
<img alt="Image illustrating the ::first-letter pseudo-element" src=http://www.w3.org/TR/selectors/initial-cap.png>
</div>
</div>
<div class=example>
The following CSS will make a drop cap initial letter span about two lines:
<pre><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<TITLE>Drop cap initial letter</TITLE>
<STYLE type="text/css">
P { font-size: 12pt; line-height: 1.2 }
P::first-letter { font-size: 200%; font-weight: bold; float: left }
SPAN { text-transform: uppercase }
</STYLE>
</HEAD>
<BODY>
<P><SPAN>The first</SPAN> few words of an article
in The Economist.</P>
</BODY>
</HTML>
</pre>
<p>This example might be formatted as follows:</p>
<div class=figure>
<img alt="Image illustrating the combined effect of the ::first-letter
and ::first-line pseudo-elements" src=http://www.w3.org/TR/selectors/first-letter.png>
</div>
<p>The <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> is:</p>
<pre><P>
<SPAN>
<P::first-letter>
T
</P::first-letter>he first
</SPAN>
few words of an article in the Economist.
</P>
</pre>
<p>Note that the <span class=css>::first-letter</span> pseudo-element tags abut the
content (i.e., the initial character), while the ::first-line
pseudo-element start tag is inserted right after the start tag of the
block element.</p>
</div>
<p>In order to achieve traditional drop caps formatting, user agents may
approximate font sizes, for example to align baselines. Also, the glyph
outline may be taken into account when formatting.</p>
<h2 class="heading settled" data-level=3 id=highlight-pseudos><span class=secno>3 </span><span class=content>
Highlight Range Pseudo-element: <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a></span><a class=self-link href=#highlight-pseudos></a></h2>
<p>The <dfn class=css data-dfn-type=selector data-export="" id=selectordef-selection>::selection<a class=self-link href=#selectordef-selection></a></dfn> pseudo-element represents
the portion of a document that has been highlighted by the user.
This also applies, for example, to selected text within an editable text field.</p>
<p class=issue id=issue-a20ca1b4><a class=self-link href=#issue-a20ca1b4></a>We want to add other types of selections, such as spelling-error highlights.</p>
<p class=issue id=issue-43364a12><a class=self-link href=#issue-43364a12></a>Active vs. inactive selections are often styled differently. Currently no way to distinguish.</p>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=root-highlight>root highlight<a class=self-link href=#root-highlight></a></dfn> is a multi-piece overlay
over the entire tree,
portions of which are selected and correspond to the <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a> pseudo-element.
Each box owns the piece of of the overlay corresponding to any text or replaced content
directly contained by the box.
For text, the corresponding overlay must cover at least the entire em box
and may extend further above/below the em box to the line box edges.
Spacing between two characters may also be part of the overlay,
in which case it belongs to the innermost element that contains both characters
and is selected when both characters are selected
For replaced content, the associated overlay must cover at least the entire replaced object,
and may extend outward to include the element’s entire content box.
The overlay may also include other other areas within the border-box of an element;
in this case, those areas belong to the innermost such element that contains the area.
<p class=issue id=issue-b6466947><a class=self-link href=#issue-b6466947></a>See
<a href=http://lists.w3.org/Archives/Public/www-style/2008Nov/0022.html>F2F minutes</a>,
<a href=http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html>dbaron’s message</a>,
<a href=http://lists.w3.org/Archives/Public/www-style/2010May/0247.html>Daniel’s thread</a>,
<a href=http://lists.w3.org/Archives/Public/www-style/2010May/0261.html>Gecko notes</a>,
<a href=http://lists.w3.org/Archives/Public/www-style/2010May/0366.html>Opera notes</a>,
<a href=http://lists.w3.org/Archives/Public/www-style/2010May/0280.html>Webkit notes</a></p>
<p>Each element draws its own portion of the highlighted overlay,
which receives the styles specified by the <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a> pseudo-element styles
for which it or one of its ancestors is the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>.
When multiple styles conflict,
the winning style is the one belonging to the innermost element
after cascading.</p>
<p class=issue id=issue-56412ce4><a class=self-link href=#issue-56412ce4></a>This could alternately be described in terms of inheritance.
So, how do we want <span class=css>inherit</span> to behave here?
Should it inherit from the parent <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a>
or the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>?
Opera does the former, Gecko/Blink the latter.</p>
<p class=advisement>
Authors wanting multiple selections styles should use
<strong><span class=css>:root::selection</span></strong>
for their document-wide selection style,
since this will allow clean overriding in descendants.
(<a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a> alone would apply to every element in the tree,
overriding the more specific styles of any ancestors.)
<h3 class="heading settled" data-level=3.1 id=highlight-styling><span class=secno>3.1 </span><span class=content>
Styling Highlighted Ranges</span><a class=self-link href=#highlight-styling></a></h3>
<p>The following properties apply to <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a> pseudo-elements:</p>
<ul>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-color title=background-color>background-color</a>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-ui-3/#cursor0 title=cursor>cursor</a> (optional)
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-ui-3/#outline0 title=outline>outline</a> and its longhands (optional)
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-decor-3/#propdef-text-decoration title=text-decoration>text-decoration</a> and its associated properties (optional)
</ul>
<p class=issue id=issue-c0c29618><a class=self-link href=#issue-c0c29618></a>What properties should be included here?
Only color and bgcolor seem supported; but text-decoration is needed for spellcheck.</p>
<p>If <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a> is not specified, the text’s actual color must be used for the highlight.
<span class=issue id=issue-0ead3129><a class=self-link href=#issue-0ead3129></a>Can we reuse <span class=css>currentColor</span> for this, now that it computes to itself?</span>
(As usual, the initial <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-color title=background-color>background-color</a> is <span class=css>transparent</span>.)</p>
<p>The UA should use the OS-default selection color
when neither <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a> nor <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-color title=background-color>background-color</a> has been specified by the author.</p>
<p class=issue id=issue-cd2ee392><a class=self-link href=#issue-cd2ee392></a>This behavior does not let us use the normal cascade for representing the OS colors
and thus violates <a href=http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html>dbaron’s #2 requirement</a>. :(
Can we do anything about that?</p>
<p>The <a class=css data-link-type=maybe href=#selectordef-selection title=::selection>::selection</a> pseudo element draws its background
over the selected portion of the element,
immediately below any positioned descendants
(i.e. just before step 8 in <a href=http://www.w3.org/TR/CSS21/zindex.html>CSS2.1§E.2</a>).
It also suppresses the drawing of any selected text
and instead redraws that text
(and any text decorations)
over that background.</p>
<p class=issue id=issue-8f96bd90><a class=self-link href=#issue-8f96bd90></a>Implementations seem to redraw text decorations and text shadows over the selection background.
This seems particularly weird if the text decoration color doesn’t match the text.
Perhaps the only thing visible should be the text itself (unless the background is transparent)
and any text decorations specified for the selection itself.
(Alternately the decorations should get the color of the selected text,
not the unselected text.)</p>
<p>For non-replaced content, the UA must honor the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a> and <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-color title=background-color>background-color</a>
(including their alpha channels) as specified.
However, for replaced content, the UA should create a semi-transparent wash
to coat the content so that it can show through the selection.
This wash should be of the specified <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#background-color title=background-color>background-color</a> if that is not <span class=css>transparent</span>,
else the specified <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-color-3/#color0 title=color>color</a>;
however the UA may adjust the alpha channel if it is opaque.</p>
<p class=issue id=issue-81c4e72d><a class=self-link href=#issue-81c4e72d></a>The wash requirement is a minor update on WebKit’s behavior. Gecko & Opera just use the default selection color for the wash.</p>
<p class=issue id=issue-a5c22c51><a class=self-link href=#issue-a5c22c51></a>This whole section needs vocabulary cleanup.</p>
<h2 class="heading settled" data-level=4 id=generated-content><span class=secno>4 </span><span class=content>
Generated Content Pseudo-elements: <a class=css data-link-type=maybe href=#selectordef-before title=::before>::before</a> and <a class=css data-link-type=maybe href=#selectordef-after title=::after>::after</a></span><a class=self-link href=#generated-content></a></h2>
<p>When their computed <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-content-3/#content title=content>content</a> value is not <span class=css>none</span>,
these pseudo-elements generate boxes
as if they were immediate children of their <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>,
and can be styled exactly like any normal document-sourced element in the document tree.
They <a data-link-type=dfn href=http://dev.w3.org/csswg/css-cascade-3/#inheritance title=inheritance>inherit</a> any inheritable properties from their <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>;
non-inheritable properties take their <a data-link-type=dfn href=http://dev.w3.org/csswg/css-cascade-3/#initial-value title="initial values">initial values</a> as usual.
<a data-biblio-type=informative data-link-type=biblio href=#biblio-css3cascade title=biblio-CSS3CASCADE>[CSS3CASCADE]</a></p>
<dl>
<dt><dfn class=css data-dfn-type=selector data-export="" id=selectordef-before>::before<a class=self-link href=#selectordef-before></a></dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>’s actual content.
<dt><dfn class=css data-dfn-type=selector data-export="" id=selectordef-after>::after<a class=self-link href=#selectordef-after></a></dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>’s actual content.
</dl>
<div class=example>
For example, the following rule inserts the string “Note: ”
before the content of every <code><p></code> element
whose <code>class</code> attribute has the value <code>note</code>:
<pre>p.note::before { content: "Note: " }</pre>
<p>Since the initial value of <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css2/visuren.html#propdef-display title=display>display</a> is <span class=css>inline</span>,
this will generate an inline box.
Like other inline children of <code><p></code>,
it will participate in <code><p></code>’s inline formatting context,
potentially sharing a line with other content.</p>
</div>
<p>As with the content of regular elements,
the generated content of <a class=css data-link-type=maybe href=#selectordef-before title=::before>::before</a> and <span class=css>:after</span> pseudo-elements
may be included in any <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> and <span class=css>::first-letter</span> pseudo-elements
applied to its <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#originating-element title="originating element">originating element</a>.</p>
<p>For compatibility with existing style sheets written against CSS Level 2 <a data-biblio-type=informative data-link-type=biblio href=#biblio-css21 title=biblio-CSS21>[CSS21]</a>,
user agents must also accept the previous one-colon notation
(<code>:before</code> and <code>:after</code>)
for these pseudo-elements.
<h2 class="heading settled" data-level=5 id=interactions><span class=secno>5 </span><span class=content>Overlapping Pseudo-element Interactions</span><a class=self-link href=#interactions></a></h2>
<div class=example id=overlapping-example><a class=self-link href=#overlapping-example></a>
Recall that
<ul>
<li>
the contents of <a class=css data-link-type=maybe href=#selectordef-before title=::before>::before</a> and <a class=css data-link-type=maybe href=#selectordef-after title=::after>::after</a> are selected
exactly as if they were normal elements in the document source tree
<li>
the <span class=css>::first-letter</span> boundaries are tightly wrapped around the first letter text,
and <span class=css>::first-letter</span> is constrained to exist solely on the first formatted line.
<li>
the <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a> start is inserted inserted just inside the containing block’s element boundary,
and its end after the close of all content on the line
</ul>
<p>The following CSS and HTML example
illustrates how overlapping pseudo-elements interact:</p>
<pre>p { color: red; font-size: 12pt }
p::first-letter { color: green; font-size: 200% }
p::first-line { color: blue }
<P>Some text that ends up on two lines</P>
</pre>
<p>The first letter of each P element will be green with a font size of ’24pt'.
The rest of the first formatted line will be blue
while the rest of the paragraph will be red.</p>
<p>Assuming that a line break will occur before the word "ends",
the <a data-link-type=dfn href=#fictional-tag-sequence title="fictional tag sequence">fictional tag sequence</a> for this fragment might be:
<pre><P>
<P::first-line>
<P::first-letter>
S
</P::first-letter>ome text that
</P::first-line>
ends up on two lines
</P>
</pre><p></p>
</div>
<h2 class="heading settled" data-level=6 id=cssom><span class=secno>6 </span><span class=content>
Additions to the CSS Object Model</span><a class=self-link href=#cssom></a></h2>
<p>Pseudo-elements should be reachable by script,
stylable from script,
and available as event targets.</p>
<p class=note><span class=note-prefix>Note </span>We may extend this
section in the future to allow creation of pseudo-elements from script.
<h3 class="heading settled" data-level=6.1 id=CSSPseudoElement-interface><span class=secno>6.1 </span><span class=content>
Interface CSSPseudoElement</span><a class=self-link href=#CSSPseudoElement-interface></a></h3>
<p>The <code>CSSPseudoElement</code> interface
allows pseudo-elements to be styleable from script
and makes them event targets.</p>
<div class=issue id=issue-b008e095><a class=self-link href=#issue-b008e095></a>
The approach in this draft
is to start with a bare minimum
for the CSSPseudoElement interface
and build up from there.
Another more radical approach
could take everything that’s common
between a pseudo-element and a node
and create a new base class
for both Node and CSSPseudoElement.
</div>
<pre class=idl>interface <dfn class=idl-code data-dfn-type=interface data-export="" data-global-name="" id=dom-csspseudoelement>CSSPseudoElement<a class=self-link href=#dom-csspseudoelement></a></dfn> {
readonly attribute unsigned long <dfn class=idl-code data-dfn-for=CSSPseudoElement data-dfn-type=attribute data-export="" data-global-name="CSSPseudoElement<interface>/ordinal<attribute>" data-readonly="" data-type="unsigned long " id=dom-csspseudoelement-ordinal>ordinal<a class=self-link href=#dom-csspseudoelement-ordinal></a></dfn>;
// the ordinal of a column is its index
readonly attribute DOMString <dfn class=idl-code data-dfn-for=CSSPseudoElement data-dfn-type=attribute data-export="" data-global-name="CSSPseudoElement<interface>/type<attribute>" data-readonly="" data-type="DOMString " id=dom-csspseudoelement-type>type<a class=self-link href=#dom-csspseudoelement-type></a></dfn>;
readonly attribute <a data-link-type=idl href=http://dev.w3.org/csswg/cssom-1/#cssstyledeclaration title=CSSStyleDeclaration>CSSStyleDeclaration</a> <dfn class=idl-code data-dfn-for=CSSPseudoElement data-dfn-type=attribute data-export="" data-global-name="CSSPseudoElement<interface>/style<attribute>" data-readonly="" data-type="CSSStyleDeclaration " id=dom-csspseudoelement-style>style<a class=self-link href=#dom-csspseudoelement-style></a></dfn>;
};
<a data-link-type=idl href=#dom-csspseudoelement title=CSSPseudoElement>CSSPseudoElement</a> implements <a data-link-type=idl href=http://dom.spec.whatwg.org/#eventtarget title=EventTarget>EventTarget</a>;
</pre>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochild-ordinal>ordinal<a class=self-link href=#dom-csspseudochild-ordinal></a></dfn> attribute
represents the ordinal of the pseudo-element for the object’s type.
It is a strictly positive integer.
The value <code>1</code> for the <code>before</code>
(or <code>after</code>, <code>letter</code> and <code>line</code>)
types represents the <a class=css data-link-type=maybe href=#selectordef-before title=::before>::before</a> (or <a class=css data-link-type=maybe href=#selectordef-after title=::after>::after</a>,
<span class=css>::first-letter</span> and <a class=css data-link-type=maybe href=#selectordef-first-line title=::first-line>::first-line</a>)
pseudo-elements.
The <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochild-type>type<a class=self-link href=#dom-csspseudochild-type></a></dfn> attribute
is a string representing the type of the pseudo-element.
This can be one of the following values:</p>
<dl>
<dt>‘before’
<dd>The pseudo-element was created before the element’s contents
<dt>‘after’
<dd>The pseudo-element was created after the element’s contents
<dt>‘letter’
<dd>The pseudo-element is the first letter of the element;
the only valid ordinal is 1.
<dt>‘line’
<dd>The pseudo-element is the first line of the element;
the only valid ordinal is 1.
<dt>‘column’
<dd>The pseudo-element is a column created by the element through
the CSS Multi-column Layout Module.
In that case its <code>ordinal</code> is
the index of column in the collection of columns created by the element.
</dl>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochild-style>style<a class=self-link href=#dom-csspseudochild-style></a></dfn> attribute
is a <code>CSSStyleDeclaration</code> <a data-biblio-type=normative data-link-type=biblio href=#biblio-cssom title=biblio-CSSOM>[CSSOM]</a>
that allows directly setting style information (inline styles) onto the pseudo-element.
Inline styles on a <code>CSSPseudoElement</code> have precedence over all
style rules styling that pseudo-element.
Issue: This should cascade like actual inline styles, not be a different thing.</p>
<p>The <a href=http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget><code>EventTarget</code></a> interface <a data-biblio-type=normative data-link-type=biblio href=#biblio-dom-level-2-events title=biblio-DOM-LEVEL-2-EVENTS>[DOM-LEVEL-2-EVENTS]</a>
must be implemented by all instances of <code>CSSPseudoElement</code>
as a conformance requirement of this module.</p>
<h3 class="heading settled" data-level=6.2 id=CSSPseudoElementList-interface><span class=secno>6.2 </span><span class=content>
Interface CSSPseudoElementList</span><a class=self-link href=#CSSPseudoElementList-interface></a></h3>
<p>The <code>CSSPseudoElementList</code> represents an ordered collection
of <code>CSSPseudoElement</code> instances.</p>
<pre class=idl>interface <dfn class=idl-code data-dfn-type=interface data-export="" data-global-name="" id=dom-csspseudoelementlist>CSSPseudoElementList<a class=self-link href=#dom-csspseudoelementlist></a></dfn> {
readonly attribute unsigned long <dfn class=idl-code data-dfn-for=CSSPseudoElementList data-dfn-type=attribute data-export="" data-global-name="CSSPseudoElementList<interface>/length<attribute>" data-readonly="" data-type="unsigned long " id=dom-csspseudoelementlist-length>length<a class=self-link href=#dom-csspseudoelementlist-length></a></dfn>;
<a data-link-type=idl href=#dom-csspseudoelement title=CSSPseudoElement>CSSPseudoElement</a> <dfn class=idl-code data-dfn-for=CSSPseudoElementList data-dfn-type=method data-export="" data-global-name="CSSPseudoElementList<interface>/item()<method>" id=dom-csspseudoelementlist-item title=item()>item<a class=self-link href=#dom-csspseudoelementlist-item></a></dfn>(unsigned long <dfn class=idl-code data-dfn-for=CSSPseudoElementList/item() data-dfn-type=argument data-export="" data-global-name="CSSPseudoElementList<interface>/item()<method>/index<argument>" id=dom-csspseudoelementlist-item-index>index<a class=self-link href=#dom-csspseudoelementlist-item-index></a></dfn>);
<a data-link-type=idl href=#dom-csspseudoelement title=CSSPseudoElement>CSSPseudoElement</a> <dfn class=idl-code data-dfn-for=CSSPseudoElementList data-dfn-type=method data-export="" data-global-name="CSSPseudoElementList<interface>/getbyordinalandtype()<method>" id=dom-csspseudoelementlist-getbyordinalandtype title=getByOrdinalAndType()>getByOrdinalAndType<a class=self-link href=#dom-csspseudoelementlist-getbyordinalandtype></a></dfn>(unsigned long <dfn class=idl-code data-dfn-for=CSSPseudoElementList/getByOrdinalAndType() data-dfn-type=argument data-export="" data-global-name="CSSPseudoElementList<interface>/getByOrdinalAndType()<method>/ordinal<argument>" id=dom-csspseudoelementlist-getbyordinalandtype-ordinal>ordinal<a class=self-link href=#dom-csspseudoelementlist-getbyordinalandtype-ordinal></a></dfn>,
DOMString <dfn class=idl-code data-dfn-for=CSSPseudoElementList/getByOrdinalAndType() data-dfn-type=argument data-export="" data-global-name="CSSPseudoElementList<interface>/getByOrdinalAndType()<method>/type<argument>" id=dom-csspseudoelementlist-getbyordinalandtype-type>type<a class=self-link href=#dom-csspseudoelementlist-getbyordinalandtype-type></a></dfn>);
// replies null if no pseudo-element does not exist for
// the requested ordinal and type
};
</pre>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochildlist-length>length<a class=self-link href=#dom-csspseudochildlist-length></a></dfn> attribute
represents the number of <code>CSSPseudoElement</code> in the
collection or zero if it is empty.
The method <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochildlist-item>item()<a class=self-link href=#dom-csspseudochildlist-item></a></dfn>
is used to retrieve a <code>CSSPseudo</code><code>Element</code> by index.
It takes one parameter being the requested index into the collection.
Its return value is the <code>CSSPseudo</code><code>Element</code>
at the requested index in the collection
or null if that is not a valid index.
The method <dfn data-dfn-type=dfn data-noexport="" id=dom-csspseudochildlist-getbyordinalandtype>getByOrdinalAndType()<a class=self-link href=#dom-csspseudochildlist-getbyordinalandtype></a></dfn>
is used to retrieve a <code>CSSPseudo</code><code>Element</code>
by its ordinal and type.
It takes two parameters: first, the requested ordinal; second a type.
Its return value is the <code>CSSPseudo</code><code>Element</code>
at the requested index in the collection
or null if there is no <code>CSSPseudo</code><code>Element</code>
in the collection for that index and type.</p>
<h3 class="heading settled" data-level=6.3 id=window-interface><span class=secno>6.3 </span><span class=content>
Addition to the <code>window</code> interface</span><a class=self-link href=#window-interface></a></h3>
<p>A new method is added to the <code>Window</code> interface to retrieve
pseudo-elements created by a given element for a given type:
<pre class=idl>partial interface <a class=idl-code data-global-name="" data-link-type=interface href=https://html.spec.whatwg.org/#window title=Window>Window</a> {
<a data-link-type=idl href=#dom-csspseudoelementlist title=CSSPseudoElementList>CSSPseudoElementList</a> <dfn class=idl-code data-dfn-for=Window data-dfn-type=method data-export="" data-global-name="Window<interface>/getpseudoelements()<method>" id=dom-window-getpseudoelements title=getPseudoElements()>getPseudoElements<a class=self-link href=#dom-window-getpseudoelements></a></dfn>(<a data-link-type=idl href=http://dom.spec.whatwg.org/#element title=Element>Element</a> <dfn class=idl-code data-dfn-for=Window/getPseudoElements() data-dfn-type=argument data-export="" data-global-name="Window<interface>/getPseudoElements()<method>/elt<argument>" id=dom-window-getpseudoelements-elt>elt<a class=self-link href=#dom-window-getpseudoelements-elt></a></dfn>,
DOMString <dfn class=idl-code data-dfn-for=Window/getPseudoElements() data-dfn-type=argument data-export="" data-global-name="Window<interface>/getPseudoElements()<method>/type<argument>" id=dom-window-getpseudoelements-type>type<a class=self-link href=#dom-window-getpseudoelements-type></a></dfn>);
};
</pre><p></p>
<p>The <dfn data-dfn-type=dfn data-noexport="" id=dom-window-getpseudochildren><code>getPseudoElements()</code><a class=self-link href=#dom-window-getpseudochildren></a></dfn> method
is used to retrieve all <code>CSSPseudoElement</code> instances
created by the element <code>elt</code> for the type <code>type</code>.
Its return value is a <code>CSSPseudoElementList</code>,
potentially empty if no pseudo-element exists for the given element and the given type.</p>
<h2 class="no-num heading settled" id=acknowledgements><span class=content>
Acknowledgements</span><a class=self-link href=#acknowledgements></a></h2>
<p>The editors would like to thank the following individuals for their
contributions, either during the conception of the specification or during
its development and specification review process:
Tab Atkins,
David Baron,
Razvan Caliman,
Chris Coyier,
Anders Grimsrud,
Vincent Hardy.</p>
<h2 class="no-ref no-num heading settled" id=conformance><span class=content>
Conformance</span><a class=self-link href=#conformance></a></h2>
<h3 class="no-ref heading settled" id=conventions><span class=content>
Document conventions</span><a class=self-link href=#conventions></a></h3>
<p>Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. <a data-biblio-type=normative data-link-type=biblio href=#biblio-rfc2119 title=biblio-RFC2119>[RFC2119]</a></p>
<p>Examples in this specification are introduced with the words "for example"
or are set apart from the normative text with <code>class="example"</code>,
like this:
<div class=example>
<p>This is an example of an informative example.</p>
</div>
<p>Informative notes begin with the word "Note" and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class=note>Note, this is an informative note.</p>
<p>Advisements are normative sections styled to evoke special attention and are
set apart from other normative text with <code><strong class="advisement"></code>, like
this:
<strong class=advisement>
UAs MUST provide an accessible alternative.
</strong>
<h3 class="no-ref heading settled" id=conformance-classes><span class=content>
Conformance classes</span><a class=self-link href=#conformance-classes></a></h3>
<p>Conformance to this specification
is defined for three conformance classes:
<dl>
<dt>style sheet
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#style-sheet>CSS
style sheet</a>.
<dt>renderer
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that interprets the semantics of a style sheet and renders
documents that use them.
<dt>authoring tool
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that writes a style sheet.
</dl>
<p>A style sheet is conformant to this specification
if all of its statements that use syntax defined in this module are valid
according to the generic CSS grammar and the individual grammars of each
feature defined in this module.
<p>A renderer is conformant to this specification
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by this specification by parsing them correctly
and rendering the document accordingly. However, the inability of a
UA to correctly render a document due to limitations of the device
does not make the UA non-conformant. (For example, a UA is not
required to render color on a monochrome monitor.)
<p>An authoring tool is conformant to this specification
if it writes style sheets that are syntactically correct according to the
generic CSS grammar and the individual grammars of each feature in
this module, and meet all other conformance requirements of style sheets
as described in this module.
<h3 class="no-ref heading settled" id=partial><span class=content>
Partial implementations</span><a class=self-link href=#partial></a></h3>
<p>So that authors can exploit the forward-compatible parsing rules to
assign fallback values, CSS renderers <strong>must</strong>
treat as invalid (and <a href=http://www.w3.org/TR/CSS21/conform.html#ignore>ignore
as appropriate</a>) any at-rules, properties, property values, keywords,
and other syntactic constructs for which they have no usable level of
support. In particular, user agents <strong>must not</strong> selectively
ignore unsupported component values and honor supported values in a single
multi-value property declaration: if any value is considered invalid
(as unsupported values must be), CSS requires that the entire declaration
be ignored.</p>
<h3 class="no-ref heading settled" id=experimental><span class=content>
Experimental implementations</span><a class=self-link href=#experimental></a></h3>
<p>To avoid clashes with future CSS features, the CSS2.1 specification
reserves a <a href=http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords>prefixed
syntax</a> for proprietary and experimental extensions to CSS.
<p>Prior to a specification reaching the Candidate Recommendation stage
in the W3C process, all implementations of a CSS feature are considered
experimental. The CSS Working Group recommends that implementations
use a vendor-prefixed syntax for such features, including those in
W3C Working Drafts. This avoids incompatibilities with future changes
in the draft.
</p>