-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
798 lines (660 loc) · 32.5 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
<h1>CSS Pseudo-Elements Module Level 4</h1>
<pre class='metadata'>
Shortname: css-pseudo
Level: 4
Status: ED
Group: csswg
ED: http://dev.w3.org/csswg/css-pseudo-4/
TR: http://www.w3.org/TR/css-pseudo-4/
Editor: Daniel Glazman, Disruptive Innovations
Editor: fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
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: typographic letter unit, Unicode general category, initial-letter
</pre>
<h2 id="intro">Introduction</h2>
<em>This section is informative.</em>
<i>Pseudo-elements</i> 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 ''::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 <i>originating element</i>
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 <i>selectors</i>,
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 <i>first formatted line</i> of its <i>originating element</i>.
<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 <i>fictional tag sequence</i> 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 <i>fictional tag sequence</i>
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 <i>fictional tag sequence</i> 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 <i>block container</i>.
The <dfn>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 <i>fictional tag sequence</i> 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 [[CSS3LINE]])
<li>any other properties defined to apply to ''::first-letter''
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 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.)
<h3 id="first-letter-pseudo">
The ::first-letter pseudo-element</h3>
The ''::first-letter'' pseudo-element represents
the first <i>typographic letter unit</i> [[!CSS3TEXT]]
on the <i>first formatted line</i> of its <i>originating element</i>,
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 [[CSS3LINE]]:
<pre>h2 + p::first-letter { initial-letter: 2; }
</pre>
</div>
Punctuation (i.e, characters that belong to the Punctuation (<code>P*</code>) <i>Unicode general category</i> [[!UAX44]])
that precedes or follows the first <i>typographic letter unit</i> 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="http://www.w3.org/TR/selectors/first-letter2.png">
</div>
As explained in [[!CSS3TEXT]],
a <i>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 ''::first-letter'' pseudo-element. [[UAX29]]
The UA should tailor its definition of <i>typographic letter unit</i>
to reflect the first-letter traditions of the <i>originating element</i>’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?
Note: Note that the first <i>typographic letter unit</i> 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 class="css">T" 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 <i>first formatted line</i>.
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 <i>fictional tag sequence</i> 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
if its 'float' property is ''none'';
otherwise, it is similar to a floated 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 [[CSS3LINE]])
<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="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>
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="http://www.w3.org/TR/selectors/first-letter.png">
</div>
The <i>fictional tag sequence</i> 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 Range Pseudo-element: ''::selection''</h2>
The <dfn>::selection</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.
Issue: We want to add other types of selections, such as spelling-error highlights.
Issue: Active vs. inactive selections are often styled differently. Currently no way to distinguish.
<p>The <dfn>root highlight</dfn> is a multi-piece overlay
over the entire tree,
portions of which are selected and correspond to the ''::selection'' 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.
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>
Each element draws its own portion of the highlighted overlay,
which receives the styles specified by the ''::selection'' pseudo-element styles
for which it or one of its ancestors is the <i>originating element</i>.
When multiple styles conflict,
the winning style is the one belonging to the innermost element
after cascading.
Issue: This could alternately be described in terms of inheritance.
So, how do we want ''inherit'' to behave here?
Should it inherit from the parent ''::selection''
or the <i>originating element</i>?
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 would apply to every element in the tree,
overriding the more specific styles of any ancestors.)
<h3 id="highlight-styling">
Styling Highlighted Ranges</h3>
The following properties apply to ''::selection'' pseudo-elements:
<ul>
<li>'color'
<li>'background-color'
<li>'cursor' (optional)
<li>'outline' and its longhands (optional)
<li>'text-decoration' and its associated properties (optional)
</ul>
Issue: What properties should be included here?
Only color and bgcolor seem supported; but text-decoration is needed for spellcheck.
If 'color' is not specified, the text's actual color must be used for the highlight.
(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 selection color
when neither 'color' nor 'background-color' has been specified by the author.
Note: This behavior does not let 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 ''::selection'' 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.
Issue: 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.)
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 the specified 'color';
however the UA may adjust the alpha channel if it is opaque.
Issue: The wash requirement is a minor update on WebKit's behavior. Gecko & Opera just use the default selection color for the wash.
Issue: This whole section needs vocabulary cleanup.
<h2 id="generated-content">
Generated Content Pseudo-elements: ''::before'' and ''::after''</h2>
When their computed 'content' value is not ''none'',
these pseudo-elements generate boxes
as if they were immediate children of their <i>originating element</i>,
and can be styled exactly like any normal document-sourced element in the document tree.
They <i title="inheritance">inherit</i> any inheritable properties from their <i>originating element</i>;
non-inheritable properties take their <i>initial values</i> as usual.
[[CSS3CASCADE]]
<dl>
<dt><dfn>::before</dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <i>originating element</i>'s actual content.
<dt><dfn>::after</dfn>
<dd>Represents a styleable child pseudo-element
immediately before the <i>originating element</i>'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 ''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 <i>originating element</i>.
<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="alt-property">
Alternative text for Generated Content: The 'alt' property</h3>
The generated content of a ::before or ::after element is not always appropriate for assistive technology. In these cases, alternative text can be provided using the 'alt' property. The 'alt' property applies only to the same elements the 'content' property applies to.
<pre class=propdef>
Name: alt
Value: none | <<string>>
Initial: none
Applies to: ::before and ::after pseudo-elements
Inherited: no
Computed Value: as specified
</pre>
<dl>
<dt>none</dt>
<dd>No alternative text</dd>
<dt><<string>></dt>
<dd>The alternative text is the <<string>>. This can be the empty string.</dd>
</dl>
When the alt property computes to anything other than none, the alternative <<string>> should be used instead of the value of the contents property by assistive technology.
<div class="example">
Here the content property is an image, so the alt property is required to provide alternative text.
<pre>
.new::before {
content: url(./img/star.png);
alt: "New!";
}
</pre>
</div>
<div class="example">
If the pseudo-element is purely decorative and its function is covered elsewhere, setting alt to the empty string can avoid reading out the decorative element. Here the ARIA attribute will be spoken as "collapsed". Without the empty string alt value, the content would also be spoken as "Black right-pointing pointer".
<pre>
.expandable::before {
content: "\25BA"; /* a.k.a. ► */
alt: "";
/* aria-expanded="false" already in DOM,
so this pseudo-element is decorative */
}
</pre>
</div>
<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 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:
<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>
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 <i>fictional tag sequence</i> 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>
</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.
<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 DOMString <a href="#dom-csspseudochild-type">type</a>;
readonly attribute <a href="http://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>
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="http://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>(DOMString 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,
DOMString 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="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.