@@ -10,7 +10,7 @@ TR: http://www.w3.org/TR/css-pseudo-4/
10
10
Editor : fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
11
11
Editor : Alan Stearns, Adobe Systems Inc., stearns@adobe.com
12
12
Abstract : This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.
13
- Ignored Terms : typographic letter unit, Unicode general category
13
+ Ignored Terms : typographic letter unit, Unicode general category, initial-letter
14
14
</pre>
15
15
16
16
<h2 id="intro">Introduction</h2>
@@ -36,11 +36,14 @@ Ignored Terms: typographic letter unit, Unicode general category
36
36
and on their syntax and interaction with other <i> selectors</i> ,
37
37
see [[!SELECTORS4]] .
38
38
39
+ <h2 id="typographic-pseudos">
40
+ Typographic Pseudo-elements</h2>
41
+
39
42
<h3 id="first-line-pseudo">
40
43
The ::first-line pseudo-element</h3>
41
44
42
45
The <dfn>::first-line</dfn> pseudo-element describes the contents of
43
- the <i> first formatted line</i> of an element.
46
+ the <i> first formatted line</i> of its <i> originating element</i> .
44
47
45
48
<div class="example">
46
49
The rule below means
@@ -125,7 +128,7 @@ The ::first-line pseudo-element</h3>
125
128
</div>
126
129
127
130
<h4 id="first-text-line">
128
- The first formatted line </h4>
131
+ Finding the First Formatted Line </h4>
129
132
130
133
In CSS, the ''::first-line'' pseudo-element
131
134
can only have an effect when attached to a <i> block container</i> .
@@ -169,6 +172,9 @@ The first formatted line</h4>
169
172
</pre>
170
173
</div>
171
174
175
+ <h4 id="first-line-styling">
176
+ Styling the First Line Pseudo-element</h4>
177
+
172
178
The ''::first-line'' pseudo-element’s generated box
173
179
behaves similar to that of an inline-level element, but with certain restrictions.
174
180
The following CSS properties apply to a ''::first-line'' pseudo-element:
@@ -184,6 +190,9 @@ The first formatted line</h4>
184
190
</ul>
185
191
User agents may apply other properties as well.
186
192
193
+ <h4 id="first-line-inheritance">
194
+ Inheritance and the ''::first-line'' Pseudo-element</h4>
195
+
187
196
During CSS inheritance, the portion of a child element that occurs on the first line
188
197
only inherits properties applicable to the ''::first-line'' pseudo-element
189
198
from the ''::first-line'' pseudo-element.
@@ -195,88 +204,67 @@ The first formatted line</h4>
195
204
<h3 id="first-letter-pseudo">
196
205
The ::first-letter pseudo-element</h3>
197
206
198
- The <dfn>::first-letter</dfn> pseudo-element represents
199
- the first <i> typographic letter unit</i> of an element,
207
+ The ''::first-letter'' pseudo-element represents
208
+ the first <i> typographic letter unit</i> [[!CSS3TEXT]]
209
+ on the <i> first formatted line</i> of its <i> originating element</i> ,
200
210
if it is not preceded by any other content
201
211
(such as images or inline tables) on its line.
202
212
The ''::first-letter'' pseudo-element can be used
203
213
to create “initial caps” and “drop caps”,
204
- which are common typographical effects.
205
- Punctuation (i.e, characters that belong to the Punctuation (<code> P</code> ) <i> Unicode general category</i> [[!UAX44]] )
214
+ which are common typographic effects.
215
+
216
+ <div class="example">
217
+ For example, the following rule creates a 2-line drop-letter
218
+ on every paragraph following a level-2 header,
219
+ using the 'initial-letter' property defined in [[CSS3LINE]] :
220
+
221
+ <pre> h2 + p::first-letter { initial-letter: 2; }
222
+ </pre>
223
+ </div>
224
+
225
+ Punctuation (i.e, characters that belong to the Punctuation (<code> P*</code> ) <i> Unicode general category</i> [[!UAX44]] )
206
226
that precedes or follows the first <i> typographic letter unit</i> must also be included
207
227
in the ''::first-letter'' pseudo-element.
208
228
209
229
<div class="figure">
210
230
<img alt="Quotes that precede the first letter should be included." src="http://www.w3.org/TR/selectors/first-letter2.png">
211
231
</div>
212
232
213
- The ''::first-letter'' also applies if the first letter is in
214
- fact a digit, e.g., the “6” in “67 million dollars is a lot of money.”
215
-
216
- Note: In some cases the ''::first-letter'' pseudo-element
217
- should include more than just the first non-punctuation character on a line.
233
+ As explained in [[!CSS3TEXT]] ,
234
+ a <i> typographic letter unit</i> can include more than one Unicode codepoint.
218
235
For example, combining characters must be kept with their base character.
219
- Additionally, some languages may have specific rules about
220
- how to treat certain letter combinations.
221
- The User-Agent definition of ''::first-letter''
222
- should include at least the default grapheme cluster as defined by UAX29
223
- and may include more than that as appropriate.
236
+ Also, languages may have additional rules
237
+ about how to treat certain letter combinations.
224
238
In Dutch, for example, if the letter combination "ij" appears at the beginning of an element,
225
239
both letters should be considered within the ''::first-letter'' pseudo-element. [[UAX29]]
240
+ The UA should tailor its definition of <i> typographic letter unit</i>
241
+ to reflect the first-letter traditions of the <i> originating element</i> ’s content language.
242
+ Issue: This is actually a problem in cases where the originating element is an ancestor
243
+ with a different content. What <em> should</em> we say here?
226
244
227
- If the letters that would form the ''::first-letter''
228
- are not in the same element,
229
- such as "‘T" in <code> <p>'<em>T...</code> ,
245
+ Note: Note that the first <i> typographic letter unit</i> may in fact
246
+ be a digit, e.g., the “6” in “67 million dollars is a lot of money.”
247
+
248
+ If the characters that would form the ''::first-letter''
249
+ are not in the same element, such as "‘<code class="css"> T" in <code> <p>'<em>T...</code> ,
230
250
the user agent may create a ''::first-letter'' pseudo-element
231
- from one of the elements, both elements,
232
- or simply not create a pseudo-element.
233
- Similarly, if the first letter(s) of the block
251
+ from one of the elements, both elements, or simply not create a pseudo-element.</code>
252
+ Additionally, if the first letter(s) of the block
234
253
are not at the start of the line (for example due to bidirectional reordering),
235
- then the user agent need not create the pseudo-element(s).
236
-
237
- <div class="example" id="overlapping-example">
238
- The following CSS and HTML example
239
- illustrates how overlapping pseudo-elements may interact.
240
- The first letter of each P element will be green with a font size of ’24pt'.
241
- The rest of the first formatted line will be blue
242
- while the rest of the paragraph will be red.
243
-
244
- <pre>
245
- p { color: red; font-size: 12pt }
246
- p::first-letter { color: green; font-size: 200% }
247
- p::first-line { color: blue }
248
-
249
- <P>Some text that ends up on two lines</P>
250
- </pre>
254
+ then the user agent need not create the pseudo-element(s).
251
255
252
- Assuming that a line break will occur before the word "ends",
253
- the <i> fictional tag sequence</i> for this fragment might be:
254
- <pre>
255
- <P>
256
- <P::first-line>
257
- <P::first-letter>
258
- S
259
- </P::first-letter>ome text that
260
- </P::first-line>
261
- ends up on two lines
262
- </P>
263
- </pre>
256
+ The ''::first-letter'' pseudo-element is contained within any ''::first-line''
257
+ pseudo-elements, and thus inherits from ''::first-line'' .
264
258
265
- Note that the ''::first-letter'' element is inside the ''::first-line'' element.
266
- Properties set on ''::first-line'' are inherited by ''::first-letter'' ,
267
- but are overridden if the same property is set on ''::first-letter'' .
268
- </div>
259
+ <h4 id="application-in-css">
260
+ Finding the First Letter</h4>
269
261
270
262
The first letter must occur on the <i> first formatted line</i> .
271
263
For example, in this HTML fragment: <code> <p><br>First...</code>
272
264
the first line doesn't contain any letters
273
- and ''::first-letter'' doesn't match anything
274
- (assuming the default style for <code> br</code> in HTML 4).
265
+ and ''::first-letter'' doesn't match anything.
275
266
In particular, it does not match the “F” of “First”.
276
267
277
- <h4 id="application-in-css">
278
- Application in CSS</h4>
279
-
280
268
In CSS, the ''::first-letter'' pseudo-element
281
269
only applies to block containers.
282
270
<span class="note"> A future version of this specification
@@ -323,6 +311,9 @@ Application in CSS</h4>
323
311
selector ''p::first-letter'' matches the "N" of "Note".
324
312
</div>
325
313
314
+ <h4 id="first-letter-styling">
315
+ Styling the ''::first-letter'' Pseudo-element</h4>
316
+
326
317
In CSS a ::first-letter pseudo-element is similar to an inline-level element
327
318
if its 'float' property is ''none'' ;
328
319
otherwise, it is similar to a floated element.
@@ -424,26 +415,81 @@ Application in CSS</h4>
424
415
approximate font sizes, for example to align baselines. Also, the glyph
425
416
outline may be taken into account when formatting.
426
417
427
- <h3 id="generated-content">
428
- The ::before and ::after pseudo-elements</h3>
429
-
430
- The <dfn>::before</dfn> and <dfn>::after</dfn> pseudo-elements
431
- can be used to describe generated content before or after
432
- an element's content.
433
- They are explained in CSS 2.1 [[!CSS21]] .
434
-
435
- When the ''::first-letter'' and ''::first-line'' pseudo-elements
436
- are applied to an element having content generated
437
- using ''::before'' or ''::after'' pseudo-elements,
438
- they apply to the first letter or line of the element including the generated content.
439
-
440
- A <a href="http://www.w3.org/TR/CSS2/syndata.html#rule-sets">CSS rule</a>
441
- using ''::before'' or ''::after'' creates a pseudo-element only if
442
- the <a href="http://www.w3.org/TR/CSS2/cascade.html#computed-value">computed
443
- values</a> of the '<a href="http://www.w3.org/TR/CSS2/generate.html#content">content</a>'
444
- property and the '<a href="http://www.w3.org/TR/css3-regions/#the-flow-from-property"><span
445
- class="property">flow-from</span></a> '
446
- property [[CSS3-REGIONS]] are not both ''none'' .
418
+ <h2 id="generated-content">
419
+ Generated Content Pseudo-elements: ''::before'' and ''::after''</h2>
420
+
421
+ When their computed 'content' value is not ''none'' ,
422
+ these pseudo-elements generate boxes
423
+ as if they were immediate children of their <i> originating element</i> ,
424
+ and can be styled exactly like any normal document-sourced element in the document tree.
425
+ They <i title="inheritance"> inherit</i> any inheritable properties from their <i> originating element</i> ;
426
+ non-inheritable properties take their <i> initial values</i> as usual.
427
+ [[CSS3CASCADE]]
428
+
429
+ <dl>
430
+ <dt> <dfn>::before</dfn>
431
+ <dd> Represents a styleable child pseudo-element
432
+ immediately before the <i> originating element</i> 's actual content.
433
+
434
+ <dt> <dfn>::after</dfn>
435
+ <dd> Represents a styleable child pseudo-element
436
+ immediately before the <i> originating element</i> 's actual content.
437
+ </dl>
438
+
439
+ <div class="example">
440
+ For example, the following rule inserts the string “Note: ”
441
+ before the content of every <code> <p></code> element
442
+ whose <code> class</code> attribute has the value <code> note</code> :
443
+
444
+ <pre> p.note::before { content: "Note: " }</pre>
445
+
446
+ Since the initial value of 'display' is ''inline'' ,
447
+ this will generate an inline box.
448
+ Like other inline children of <code> <p></code> ,
449
+ it will participate in <code> <p></code> ’s inline formatting context,
450
+ potentially sharing a line with other content.
451
+ </div>
452
+
453
+ As with the content of regular elements,
454
+ the generated content of ''::before'' and '':after'' pseudo-elements
455
+ may be included in any ''::first-line'' and ''::first-letter'' pseudo-elements
456
+ applied to its <i> originating element</i> .
457
+
458
+ <p> For compatibility with existing style sheets written against CSS Level 2 [[CSS21]] ,
459
+ user agents must also accept the previous one-colon notation
460
+ (<code> :before</code> and <code> :after</code> )
461
+ for these pseudo-elements.
462
+
463
+ <h2 id="interactions">Overlapping Pseudo-element Interactions</h2>
464
+
465
+ <div class="example" id="overlapping-example">
466
+ The following CSS and HTML example
467
+ illustrates how overlapping pseudo-elements may interact.
468
+ The first letter of each P element will be green with a font size of ’24pt'.
469
+ The rest of the first formatted line will be blue
470
+ while the rest of the paragraph will be red.
471
+
472
+ <pre>
473
+ p { color: red; font-size: 12pt }
474
+ p::first-letter { color: green; font-size: 200% }
475
+ p::first-line { color: blue }
476
+
477
+ <P>Some text that ends up on two lines</P>
478
+ </pre>
479
+
480
+ Assuming that a line break will occur before the word "ends",
481
+ the <i> fictional tag sequence</i> for this fragment might be:
482
+ <pre>
483
+ <P>
484
+ <P::first-line>
485
+ <P::first-letter>
486
+ S
487
+ </P::first-letter>ome text that
488
+ </P::first-line>
489
+ ends up on two lines
490
+ </P>
491
+ </pre>
492
+ </div>
447
493
448
494
<h2 id="cssom">
449
495
Additions to the CSS Object Model</h2>
0 commit comments