Skip to content

Commit 683cfb0

Browse files
committed
[css-pseudo-4] Rewrite ::first-letter section.
1 parent 3066e2f commit 683cfb0

File tree

1 file changed

+85
-59
lines changed

1 file changed

+85
-59
lines changed

css-pseudo-4/Overview.bs

Lines changed: 85 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ The ::first-letter pseudo-element</h3>
278278

279279
The <dfn>::first-letter</dfn> pseudo-element represents
280280
the first <a>typographic letter unit</a> [[!CSS-TEXT-3]]
281-
on the <a>first formatted line</a> of its <a>originating element</a>,
282-
if it is not preceded by any other content
283-
(such as images or inline tables) on its line.
281+
on the <a>first formatted line</a> of its <a>originating element</a>.
284282
The ''::first-letter'' pseudo-element can be used
285283
to create “initial caps” and “drop caps”,
286284
which are common typographic effects.
@@ -298,7 +296,7 @@ The ::first-letter pseudo-element</h3>
298296
that precedes or follows the first <a>typographic letter unit</a>
299297
and any intervening space separators
300298
(characters that belong to the <code>Zs</code> Unicode general category [[!UAX44]])
301-
must also be included
299+
must also be included as part of the <dfn>first-letter text</dfn>
302300
in the ''::first-letter'' pseudo-element.
303301

304302
<div class="figure">
@@ -315,79 +313,107 @@ The ::first-letter pseudo-element</h3>
315313
about how to treat certain letter combinations.
316314
In Dutch, for example, if the letter combination "ij" appears at the beginning of an element,
317315
both letters should be considered within the ''::first-letter'' pseudo-element. [[UAX29]]
318-
The UA should tailor its definition of <a>typographic letter unit</a>
316+
When selecting the [=first-letter text=],
317+
the UA should tailor its definition of <a>typographic letter unit</a>
319318
to reflect the first-letter traditions of the ''::first-letter'' pseudo-element’s <em>containing block</em>’s content language.
320319

321-
If the characters that would form the ''::first-letter''
322-
are not in the same element, such as <code>‘T</code> in <code>&lt;p&gt;‘&lt;em&gt;T...</code>,
323-
the user agent may create a ''::first-letter'' pseudo-element
324-
from one of the elements, both elements, or simply not create a pseudo-element.</code>
325-
Additionally, if the first letter(s) of the block
326-
are not at the start of the line (for example due to bidirectional reordering),
327-
then the user agent need not create the pseudo-element(s).
328-
329-
The ''::first-letter'' pseudo-element is contained within any ''::first-line''
330-
pseudo-elements, and thus inherits from ''::first-line''.
331-
332320
<h4 id="first-letter-application">
333-
Finding the First Letter</h4>
334-
335-
The first letter must occur on the <a>first formatted line</a>.
336-
For example, in this HTML fragment: <code>&lt;p&gt;&lt;br&gt;First...</code>
337-
the first line doesn't contain any letters
338-
and ''::first-letter'' doesn't match anything.
339-
In particular, it does not match the “F” of “First”.
340-
341-
In CSS, the ''::first-letter'' pseudo-element
342-
only applies to block containers.
343-
<span class="note">A future version of this specification
344-
may allow this pseudo-element to apply to more display types.</span>
345-
The ''::first-letter'' pseudo-element can be used
346-
with all such elements that contain text,
347-
or that have a descendant in the same flow that contains text.
348-
A user agent should act as if the fictional start tag
349-
of the ::first-letter pseudo-element
350-
is just before the first text of the element,
351-
even if that first text is in a descendant.
321+
Finding the First Letter Text</h4>
322+
323+
As with ''::first-line'',
324+
the ''::first-letter'' pseudo-element
325+
can only have an effect when attached to a [=block container=].
326+
Its [=first-letter text=] is the first such [=inline-level content=]
327+
participating in the [=inline formatting context=]
328+
of its [=originating element=]’s [=first formatted line=],
329+
if it is not preceded by any other in-flow content
330+
(such as images or inline tables) on its line.
331+
332+
For this purpose, any [=marker boxes=] are ignored,
333+
as if they were out-of-flow.
334+
However, if an element has in-flow ''::before'' or ''::after'' content,
335+
the [=first-letter text=] is selected from the content of the element
336+
<em>including</em> that generated content.
352337

353338
<div class="example">
354339
Example:
355-
The <a>fictional tag sequence</a> for this HTML fragment:
340+
After the rule ''p::before {content: "Note: "}'', the
341+
selector ''p::first-letter'' matches the "N" of "Note".
342+
</div>
343+
344+
If no such text exists,
345+
then there is no [=first-letter text=]
346+
and no ''::first-letter'' pseudo-element.
347+
348+
Note: When the [=first formatted line=] is empty,
349+
''::first-letter'' will not match anything.
350+
For example, in this HTML fragment:
351+
<code>&lt;p&gt;&lt;br&gt;First...</code>
352+
the first line doesn't contain any letters,
353+
so ''::first-letter'' doesn't match anything.
354+
In particular, it does not match the “F” of “First”,
355+
which is on the second line.
356+
357+
Note: As with ''::first-line'',
358+
the [=first-letter text=] of a [=block container=]
359+
that does not participate in a [=block formatting context=]
360+
cannot be the [=first-letter text=] of an ancestor element.
361+
Thus, in <code>&lt;DIV&gt;&lt;P STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt; etcetera&lt;/DIV&gt;</code>
362+
the first letter of the <code>DIV</code> is not the letter “H”.
363+
In fact, the <code>DIV</code> doesn't have a first letter,
364+
as its [=first formatted line=] contains no content besides the inline block.
365+
366+
<h4 id="first-letter-tree">
367+
Inheritance and Box Tree Structure of the ''::first-letter'' Pseudo-element</h4>
368+
369+
The ''::first-letter'' pseudo-element is wrapped
370+
immediately around the [=first-letter text=] it represents,
371+
even if that text is in a descendant.
372+
When a [=first-letter text=] is represented by multiple ''::first-letter" pseudo-elements,
373+
they are nested in the same order as their [=originating elements=].
374+
[=Inheritance=] behaves accordingly.
375+
376+
<div class="example">
377+
Consider the following markup:
378+
356379
<pre>
357380
&lt;div&gt;
358-
&lt;p&gt;The first text.
381+
&lt;p&gt;The first text.
382+
&lt;/div&gt;
359383
</pre>
360-
is:
384+
385+
If we assume a [=fictional tag sequence=]
386+
to represent the elements’ ''::first-letter'' pseudo-elements,
387+
it would be something like:
388+
361389
<pre>
362390
&lt;div&gt;
363-
&lt;p&gt;&lt;div::first-letter&gt;&lt;p::first-letter&gt;T&lt;/...&gt;&lt;/...&gt;he first text.
391+
&lt;p&gt;&lt;div::first-letter&gt;&lt;p::first-letter&gt;T&lt;/&hellip;&gt;&lt;/&hellip;&gt;he first text.
392+
&lt;/div&gt;
364393
</pre>
365394
</div>
366395
367-
In CSS the first letter of a table-cell or inline-block
368-
cannot be the first letter of an ancestor element.
369-
Thus, in <code>&lt;DIV&gt;&lt;P STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt; etcetera&lt;/DIV&gt;</code>
370-
the first letter of the <code>DIV</code> is not the letter "H".
371-
In fact, the <code>DIV</code> doesn't have a first letter.
372-
If an element is a [=list item=]
373-
the ''::first-letter'' applies
374-
to the first letter in the principal box <em>after</em> the marker.
375-
User-Agents may ignore ''::first-letter''
376-
on list items with ''list-style-position: inside''.
377-
If an element has ''::before'' or ''::after'' content,
378-
the ''::first-letter'' applies to the first letter of the
379-
element <em>including</em> that content.
380-
381-
<div class="example">
382-
Example:
383-
After the rule ''p::before {content: "Note: "}'', the
384-
selector ''p::first-letter'' matches the "N" of "Note".
385-
</div>
396+
If the characters that would form the [=first-letter text=]
397+
are not all in the same element
398+
(as the <code>‘T</code> in <code>&lt;p&gt;‘&lt;em&gt;T...</code>),
399+
the user agent may create a ''::first-letter'' pseudo-element
400+
from one of the elements, or all elements,
401+
or simply not create a pseudo-element.
402+
Additionally, if the [=first-letter text=]
403+
is not at the start of the line
404+
(for example due to bidirectional reordering,
405+
or due to a [=list item=] [=marker=] with ''list-style-position: inside''),
406+
then the user agent is not required to create the pseudo-element(s).
407+
408+
A ''::first-letter'' pseudo-element is contained within
409+
any ''::first-line'' pseudo-elements,
410+
and thus inherits (potentially indirectly) from ''::first-line'',
411+
the same as any [=inline box=] on the same line.
386412
387413
<h4 id="first-letter-styling">
388414
Styling the ''::first-letter'' Pseudo-element</h4>
389415
390-
In CSS a ::first-letter pseudo-element is similar to an inline-level element.
416+
In CSS a ::first-letter pseudo-element is similar to an [=inline box=].
391417
The following properties that apply to ''::first-letter'' pseudo-elements:
392418
393419
<ul>

0 commit comments

Comments
 (0)