-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
939 lines (781 loc) · 37.7 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
<h1>CSS Pseudo-Elements Module Level 4</h1>
<pre class='metadata'>
Shortname: css-pseudo
Level: 4
Status: ED
Work Status: Exploring
Group: csswg
ED: https://drafts.csswg.org/css-pseudo-4/
TR: https://www.w3.org/TR/css-pseudo-4/
Previous Version: https://www.w3.org/TR/2016/WD-css-pseudo-4-20160607/
Previous Version: https://www.w3.org/TR/2015/WD-css-pseudo-4-20150115/
!Issues List: <a href="https://drafts.csswg.org/css-pseudo/#issues-index">Tracked in Editor's Draft</a>
Editor: Daniel Glazman, Disruptive Innovations
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Alan Stearns, Adobe Systems Inc., stearns@adobe.com
Abstract: This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.
Ignored Terms: initial-letter, PseudoElement, pseudo(), selectors
Default Highlight: css
</pre>
<pre class="link-defaults">
spec:css-color-3; type:value; text:currentcolor
spec:css-color-3; type:property; text:color
</pre>
<h2 id="intro">Introduction</h2>
<em>This section is informative.</em>
<a>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,
they 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 ''::first-line'' 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.
Each pseudo-element is associated with an <a>originating element</a>
and has syntax of the form ''::name-of-pseudo''.
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>selectors</a>,
see [[!SELECTORS4]].
<h2 id="typographic-pseudos">
Typographic Pseudo-elements</h2>
<h3 id="first-line-pseudo">
The ::first-line pseudo-element</h3>
The <dfn>::first-line</dfn> pseudo-element describes the contents of
the <a>first formatted line</a> of its <a>originating element</a>.
<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>
The selector ''p::first-line''
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.
</div>
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.
<div class="example">
For example, given an ordinary HTML [[HTML5]] 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>
The lines might be broken as follows:
<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>
This paragraph might be “rewritten” by user agents
to include a <dfn>fictional tag sequence</dfn> to represent ''::first-line''.
This <a>fictional tag sequence</a> helps to show how properties are inherited.
<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>
If a pseudo-element breaks up a real element,
the desired effect can often be described by a <a>fictional tag sequence</a>
that closes and then re-opens the element.
<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>
the user agent could simulate start and end tags for <code>span</code>
when inserting the <a>fictional tag sequence</a> for ''::first-line''
to get the correct inheritance behavior.
<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 id="first-text-line">
Finding the First Formatted Line</h4>
In CSS, the ''::first-line'' pseudo-element
can only have an effect when attached to a <a>block container</a>.
The <dfn export>first formatted line</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).
<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>
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".
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.
A user agent must act as if the fictional start tags of a ''::first-line'' pseudo-element
were nested just inside the innermost enclosing block-level element.
<div class="example">
For example, the <a>fictional tag sequence</a> for
<pre>
<DIV>
<P>First paragraph</P>
<P>Second paragraph</P>
</DIV>
</pre>
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>
</div>
<h4 id="first-line-styling">
Styling the First Line Pseudo-element</h4>
The ''::first-line'' 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 ''::first-line'' pseudo-element:
<ul>
<li>all font properties (see [[CSS3-FONTS]])
<li>the 'color' and 'opacity' properties (see [[CSS3COLOR]])
<li>all background properties (see [[CSS3BG]])
<li>any typesetting properties that apply to inline elements (see [[CSS3TEXT]])
<li>all text decoration properties (see [[CSS3-TEXT-DECOR]])
<li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
<li>any other properties defined to apply to ''::first-line''
by their respective specifications
</ul>
User agents may apply other properties as well.
<h4 id="first-line-inheritance">
Inheritance and the ''::first-line'' Pseudo-element</h4>
During CSS inheritance, the portion of a child element that occurs on the first line
only inherits properties applicable to the ''::first-line'' pseudo-element
from the ''::first-line'' pseudo-element.
For all other properties inheritance 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.)
<h3 id="first-letter-pseudo">
The ::first-letter pseudo-element</h3>
The <dfn>::first-letter</dfn> pseudo-element represents
the first <a>typographic letter unit</a> [[!CSS3TEXT]]
on the <a>first formatted line</a> of its <a>originating element</a>,
if it is not preceded by any other content
(such as images or inline tables) on its line.
The ''::first-letter'' pseudo-element can be used
to create “initial caps” and “drop caps”,
which are common typographic effects.
<div class="example">
For example, the following rule creates a 2-line drop-letter
on every paragraph following a level-2 header,
using the 'initial-letter' property defined in [[CSS-INLINE-3]]:
<pre>h2 + p::first-letter { initial-letter: 2; }
</pre>
</div>
Punctuation (i.e, characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a> [[!UAX44]])
that precedes or follows the first <a>typographic letter unit</a> must also be included
in the ''::first-letter'' pseudo-element.
<div class="figure">
<img alt="Quotes that precede the first letter should be included." src="https://www.w3.org/TR/selectors/first-letter2.png">
</div>
As explained in [[!CSS3TEXT]],
a <a>typographic letter unit</a> 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 ''::first-letter'' pseudo-element. [[UAX29]]
The UA should tailor its definition of <a>typographic letter unit</a>
to reflect the first-letter traditions of the ''::first-letter'' pseudo-element’s <em>containing block</em>’s content language.
Note: Note that the first <a>typographic letter unit</a> may in fact
be a digit, e.g., the “6” in “67 million dollars is a lot of money.”
If the characters that would form the ''::first-letter''
are not in the same element, such as <code>‘T</code> in <code><p>‘<em>T...</code>,
the user agent may create a ''::first-letter'' 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).
The ''::first-letter'' pseudo-element is contained within any ''::first-line''
pseudo-elements, and thus inherits from ''::first-line''.
<h4 id="application-in-css">
Finding the First Letter</h4>
The first letter must occur on the <a>first formatted line</a>.
For example, in this HTML fragment: <code><p><br>First...</code>
the first line doesn't contain any letters
and ''::first-letter'' doesn't match anything.
In particular, it does not match the “F” of “First”.
In CSS, the ''::first-letter'' 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 ''::first-letter'' 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.
<div class="example">
Example:
The <a>fictional tag sequence</a> for this HTML fragment:
<pre>
<div>
<p>The first text.
</pre>
is:
<pre>
<div>
<p><div::first-letter><p::first-letter>T</...></...>he first text.
</pre>
</div>
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 (''display: list-item''),
the ''::first-letter'' applies
to the first letter in the principal box <em>after</em> the marker.
User-Agents may ignore ''::first-letter''
on list items with ''list-style-position: inside''.
If an element has ''::before'' or ''::after'' content,
the ''::first-letter'' applies to the first letter of the
element <em>including</em> that content.
<div class="example">
Example:
After the rule ''p::before {content: "Note: "}'', the
selector ''p::first-letter'' matches the "N" of "Note".
</div>
<h4 id="first-letter-styling">
Styling the ''::first-letter'' Pseudo-element</h4>
In CSS a ::first-letter pseudo-element is similar to an inline-level element.
The following properties that apply to ''::first-letter'' pseudo-elements:
<ul>
<li>all font properties (see [[CSS3-FONTS]])
<li>the 'color' and 'opacity' properties (see [[CSS3COLOR]])
<li>all background properties (see [[CSS3BG]])
<li>any typesetting properties that apply to inline elements (see [[CSS3TEXT]])
<li>all text decoration properties (see [[CSS3-TEXT-DECOR]])
<li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
<li>margin and padding properties (see [[CSS21]])
<li>border properties and 'box-shadow' (see [[CSS3BG]])
<li>any other properties defined to apply to ''::first-letter''
by their respective specifications
</ul>
User agents may apply other properties as well.
Note: In previous levels of CSS,
User Agents were allowed to choose a line height, width and height based on the shape of the letter,
approximate font sizes,
or to take the glyph outline into account when formatting.
This possibility has been intentionally removed,
as it proved to be a poor solution for the intended use case (Drop Caps),
yet caused interoperability problems.
<div class="example">
Example:
This CSS and HTML example shows a possible rendering of an initial cap.
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="https://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>
This example might be formatted as follows:
<div class="figure">
<img alt="Image illustrating the combined effect of the ::first-letter
and ::first-line pseudo-elements" src="https://www.w3.org/TR/selectors/first-letter.png">
</div>
The <a>fictional tag sequence</a> is:
<pre>
<P>
<SPAN>
<P::first-letter>
T
</P::first-letter>he first
</SPAN>
few words of an article in the Economist.
</P>
</pre>
Note that the ''::first-letter'' 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.
</div>
<h2 id="highlight-pseudos">
Highlight Pseudo-elements</h2>
<h3 id="highlight-selectors">
Selecting Highlighted Content: the ''::selection'', ''::inactive-selection'', ''::spelling-error'', and ''::grammar-error'' pseudo-elements</h3>
The <dfn>highlight pseudo-elements</dfn>
represent portions of a document that have been highlighted in some way.
<dl export>
<dt><dfn>::selection</dfn>
<dt><dfn>::inactive-selection</dfn>
<dd>
The ''::selection'' and ''::inactive-selection'' pseudo-elements represent
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.
''::selection'' applies to active selections,
wherease ''::inactive-selection'' applies to inactive selections
(e.g. when the document window is inactive and therefore not receiving events).
<dt><dfn>::spelling-error</dfn>
<dd>
The ''::spelling-error'' pseudo-element represents
a portion of text that has been flagged by the user agent as misspelled.
<dt><dfn>::grammar-error</dfn>
<dd>
The ''::grammar-error'' pseudo-element represents
a portion of text that has been flagged by the user agent as grammatically incorrect.
</dl>
The following addition is made to the default UA stylesheet:
<pre><code class="lang-css">
::spelling-error { text-decoration-line: spelling-error; }
::grammar-error { text-decoration-line: grammar-error; }
</code></pre>
Note: A future level of CSS may introduce ways to create
custom highlight pseudo-elements.
<h3 id="highlight-styling">
Styling Highlights</h3>
The following properties apply to the <a>highlight pseudo-elements</a>:
<ul>
<li>'color'
<li>'background-color'
<li>'cursor'
<li>'caret-color'
<li>'outline' and its longhands
<li>'text-decoration' and its associated properties
<li>'text-emphasis-color'
<li>'text-shadow'
</ul>
Issue: Are there any other properties that should be included here?
Note: Historically (and at the time of writing)
only 'color' and 'background-color' have been interoperably supported.
If 'color' is not specified, the text (and text decoration)'s
unselected color must be used for the highlighted text.
(As usual, the initial 'background-color' is ''transparent''.)
Issue: Can we reuse ''currentColor'' for this, now that it computes to itself?
The UA should use the OS-default highlight colors
when neither 'color' nor 'background-color' has been specified by the author.
Note: This paired-cascading behavior
does not allow <a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">using the normal cascade</a>
to represent the OS default selection colors.
However it has been interoperably implemented in browsers
and is thus probably a Web-compatibility requirement.
The 'color' property specifies the color of both the text
and all line decorations (underline, overline, line-through)
applied to the text.
Note: Because 'text-emphasis-color' defaults to ''currrentColor'',
it will by default also set the color of the the emphasis marks.
<h3 id=highlight-bounds>
Area of a Highlight</h3>
<p>For each type of highlighting (see [[#highlight-selectors]])
there exists a single <dfn>highlight overlay</dfn> for the entire document,
the active portions of which are represented
by the corresponding <a>highlight pseudo-element</a>.
Each box owns the piece of the overlay corresponding to any text or replaced content
directly contained by the box.
<ul>
<li>
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 area,
in which case it belongs to the innermost element that contains both characters
and is selected when both characters are selected.
<li>
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.
<li>
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.
</ul>
Issue: 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>
Issue: Not sure if this is the correct way of describing the way things work.
<h3 id=highlight-cascade>
Cascading and Per-Element Highlight Styles</h3>
Each element draws its own portion of the <a>highlight overlay</a>,
which receives the styles specified by the <a>highlight pseudo-element</a> styles
for which that element or one of its ancestors is the <a>originating element</a>.
When multiple styles conflict,
the winning style is the one belonging to the innermost element
after cascading.
<div class="example">
For example, if the following rules were applied:
<pre>
p::selection { color: yellow; background: green; }
p > em::selection { color: orange; }
em::selection { color: red; }
</pre>
to the following markup:
<pre>
<p>Highlight this <em>and this</em>.</p>
</pre>
The highlight would be green throughout,
with yellow text outside the <code><em></code> element
and orange text inside it.
</div>
Issue: This could alternately be described in terms of inheritance.
The observable differences would be in how ''inherit'' and ''unset'' behave.
Should it inherit from the parent ''::selection''
or the <a>originating element</a>?
Opera does the former, Gecko/Blink the latter.
<p class="advisement">
Authors wanting multiple selections styles should use
<strong>'':root::selection''</strong>
for their document-wide selection style,
since this will allow clean overriding in descendants.
''::selection'' alone applies to every element in the tree,
overriding the more specific styles of any ancestors.
<div class="example">
For example, if an author specified
<pre>
::selection { background: blue; }
p.warning { background: red; }
</pre>
and the document included
<pre>
<p class="warning">Some <strong>very important information</strong></p>
</pre>
The highlight would be blue around “very important information”
because the <code><strong></code> element´s ''::selection''
also matches the ''::selection { background: blue; }'' rule.
(Remember that ''*'' is implied when a tag selector is missing.)
The style rules that would give the intended behavior are
<pre>
:root::selection { background: blue; }
p.warning { background: red; }
</pre>
</div>
<h3 id="highlight-painting">
Painting the Highlight</h3>
Each <a>highlight pseudo-element</a> draws its background
over the active portion of the overlay,
painting it
immediately below any positioned descendants
(i.e. just before step 8 in <a href="https://www.w3.org/TR/CSS21/zindex.html">CSS2.1§E.2</a>).
It also suppresses the drawing of any selected text
(and any text decorations applied to that text)
and instead redraws that text
(and its decorations)
over the <a>highlight overlay</a> background
using the specified 'color'.
Issue: What should happen with text shadows?
Drawing them in their original color is disconcerting if that color is not a shade of gray.
For non-replaced content, the UA must honor the 'color' and 'background-color'
(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 'background-color' if that is not ''transparent'',
else of the specified 'color';
however the UA may adjust the alpha channel if it is opaque.
The ''::selection'' overlay is drawn
over the ''::spelling-error'' overlay
which is drawn over the ''::grammar-error'' overlay.
<h3 id="highlight-security">
Security and Privacy Considerations</h3>
Because the styling of spelling and grammar errors
can leak information about the contents of a user's dictionary
(which can include the user's name and even includes the contents of his/her address book!)
UAs that implement ''::spelling-error'' and ''::grammar-error''
must prevent pages from being able to read
the styling of such highlighted segments.
<h2 id="treelike">
Tree-Abiding Pseudo-elements</h2>
<dfn lt="tree-abiding|tree-abiding pseudo-element">Tree-abiding pseudo-elements</dfn> always fit within the box tree.
They <a lt="inheritance">inherit</a> any inheritable properties from their <a>originating element</a>;
non-inheritable properties take their <a>initial values</a> as usual.
[[CSS3CASCADE]]
<h3 id="generated-content">
Generated Content Pseudo-elements: ''::before'' and ''::after''</h3>
When their computed 'content' value is not ''content/none'',
these pseudo-elements generate boxes
as if they were immediate children of their <a>originating element</a>,
and can be styled exactly like any normal document-sourced element in the document tree.
<dl>
<dt><dfn>::before</dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <a>originating element</a>'s actual content.
<dt><dfn>::after</dfn>
<dd>Represents a styleable child pseudo-element
immediately after the <a>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>
Since the initial value of 'display' is ''display/inline'',
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.
</div>
As with the content of regular elements,
the generated content of ''::before'' and '':after'' pseudo-elements
may be included in any ''::first-line'' and ''::first-letter'' pseudo-elements
applied to its <a>originating element</a>.
<p>For compatibility with existing style sheets written against CSS Level 2 [[CSS21]],
user agents must also accept the previous one-colon notation
(<code>:before</code> and <code>:after</code>)
for these pseudo-elements.
<h3 id="marker-pseudo">
List Markers: the ''::marker'' pseudo-element</h3>
The <dfn>::marker</dfn> pseudo-element represents
the automatically generated marker box of a list item.
(See ''display: list-item''.)
The following CSS properties apply to a ''::marker'' pseudo-element:
<ul>
<li>all font properties (see [[CSS3-FONTS]])
<li>the 'color' property (see [[CSS3COLOR]])
<li>the 'text-combine-upright' property (see [[CSS3-WRITING-MODES]])
</ul>
<p class="note">
It is expected that future specifications will extend this list of properties;
however at the moment marker box layout is not fully defined,
so only these properties are allowed.
UAs must add the following rule to their default style sheet:
<pre>::marker { font-variant-numeric: tabular-nums; }</pre>
<h3 id="placeholder-pseudo">
Placeholder Input: the ''::placeholder'' pseudo-element</h3>
The <dfn>::placeholder</dfn> pseudo-element represents
placeholder text in an input field:
text that represents the input
and provides a hint to the user on how to fill out the form.
For example, a date-input field
might have the placeholder text “YYYY/MM/DD”
to clarify that numeric dates are to be entered in year-month-day order.
All properties that apply to the ''::first-line'' pseudo-element
also apply to the ''::placeholder'' pseudo-element.
In interactive media, placeholder text is often hidden once the user has entered input;
however this is not a requirement, and both the input value and the placeholder text may be visible simultaneously.
The exact behavior is UA-defined.
Note that in static media (such as print)
placeholder text will be present even after the user has entered input.
Issue: Authors seem to want 'text-align' on the list of supported properties.
See e.g. <a href="http://css-tricks.com/almanac/selectors/p/placeholder/">comments here</a>.
<h2 id="interactions">
Overlapping Pseudo-element Interactions</h2>
<div class="example" id="overlapping-example">
Recall that
<ul>
<li>
the contents of ''::before'' and ''::after'' are selected
exactly as if they were normal elements in the document source tree
<li>
the ''::first-letter'' boundaries are tightly wrapped around the first letter text,
and ''::first-letter'' is constrained to exist solely on the first formatted line.
<li>
the ''::first-line'' start is inserted just inside the containing block's element boundary,
and its end after the close of all content on the line
</ul>
The following CSS and HTML example
illustrates how overlapping pseudo-elements interact:
<xmp class="lang-html">
<style>
p { color: red; font-size: 12pt }
p::first-letter { color: green; font-size: 200% }
p::first-line { color: blue }
</style>
<p>Some text that ends up on two lines</p>
</xmp>
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.
Assuming that a line break will occur before the word "ends",
the <a>fictional tag sequence</a> for this fragment might be:
<xmp class="lang-html">
<p>
<p::first-line>
<p::first-letter>
S
</p::first-letter>
ome text that
</p::first-line>
ends up on two lines
</p>
</xmp>
</div>
<h2 id="cssom">
Additions to the CSS Object Model</h2>
Pseudo-elements should be reachable by script,
stylable from script,
and available as event targets.
<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.
Issue: This entire section is a starting point for discussion.
Feedback is welcome.
Implementations, at this point, are not,
as we are not yet sure of our approach.
Issue: This needs to be merged with the alternative
{{PseudoElement}} and {{Element/pseudo()}} proposal.
<h3 id="CSSPseudoElement-interface">
Interface CSSPseudoElement</h3>
The <code>CSSPseudoElement</code> interface
allows pseudo-elements to be styleable from script
and makes them event targets.
<div class="issue">
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 CSSPseudoElement {
readonly attribute CSSOMString <a href="#dom-csspseudochild-type">type</a>;
readonly attribute <a href="https://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration">CSSStyleDeclaration</a> <a href="#dom-csspseudochild-style">style</a>;
};
CSSPseudoElement implements EventTarget;
</pre>
The <dfn id="dom-csspseudochild-type">type</dfn> attribute
is a string representing the type of the pseudo-element.
This can be one of the following values:
<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.
<dt>‘line’
<dd>The pseudo-element is the first line of the element.
<dt>‘selection’
<dd>The selection pseudo-element for the element.
</dl>
Issue: Why are these strings different from the name of the pseudo-element?
The <dfn id="dom-csspseudochild-style">style</dfn> attribute
is a <code>CSSStyleDeclaration</code> [[!CSSOM]]
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.
The <a href="https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget"><code>EventTarget</code></a> interface [[!DOM-LEVEL-2-EVENTS]]
must be implemented by all instances of <code>CSSPseudoElement</code>
as a conformance requirement of this module.
<h3 id="CSSPseudoElementList-interface">
Interface CSSPseudoElementList</h3>
The <code>CSSPseudoElementList</code> represents an ordered collection
of <code>CSSPseudoElement</code> instances.
<pre class="idl">
interface CSSPseudoElementList {
readonly attribute unsigned long <a href="#dom-csspseudochildlist-length">length</a>;
CSSPseudoElement <a href="#dom-csspseudochildlist-item">item</a>(unsigned long index);
CSSPseudoElement <a href="#dom-csspseudochildlist-getbytype">getByType</a>(CSSOMString type);
// replies null if no pseudo-element exists for
// the requested type
};
</pre>
The <dfn id="dom-csspseudochildlist-length">length</dfn> attribute
represents the number of <code>CSSPseudoElement</code> in the
collection or zero if it is empty.
The method <dfn id="dom-csspseudochildlist-item">item()</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 id="dom-csspseudochildlist-getbytype">getByType()</dfn>
is used to retrieve a <code>CSSPseudo</code><code>Element</code>
by its type.
Its return value is the <code>CSSPseudo</code><code>Element</code>
in the collection that matches the type
or null if there is no <code>CSSPseudo</code><code>Element</code>
in the collection for that type.
<h3 id="window-interface">
Addition to the <code>window</code> interface</h3>
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 Window {
CSSPseudoElementList <a href="#dom-window-getpseudochildren">getPseudoElements</a>(Element elt,
CSSOMString type);
};
</pre>
The <dfn id="dom-window-getpseudochildren"><code>getPseudoElements()</code></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.
<h2 class="no-num" id="changes">
Changes</h2>
Changes since the <a href="https://www.w3.org/TR/2015/WD-css-pseudo-4-20150115/">15 January 2015 Working Draft</a> include:
<ul>
<li>Addition of the ''::marker'' pseudo-element.
<li>Removed special handling of floated ''::first-letter'' in favor of <a href="https://www.w3.org/TR/css-inline-3/#initial-letter-styling">initial letter styling</a>. [[CSS-INLINE-3]]
<li>Added ''::inactive-selection''.
<li>Defined handling of text decorations on ''::selection'' to match IE's more sensible behavior.
<li>Links to pseudo-element OM design discussions.
<li>Various minor clarifications.
<li>Use ''spelling-error'' and ''grammar-error'' with ''::spelling-error'' and ''::grammar-error'' in the UA stylesheet.
</ul>
<h2 class="no-num" id="acknowledgements">
Acknowledgements</h2>
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.