Skip to content

Commit f355c32

Browse files
committed
[css-pseudo] Clean up ::first-letter and ::before/::after definitions.
--HG-- rename : css-pseudo/Overview.src.html => css-pseudo/Overview.bs extra : rebase_source : fe2dbf98cc1224cfc0be1e3257652cde1bb7cc9d
1 parent 1f3c1db commit f355c32

File tree

2 files changed

+312
-215
lines changed

2 files changed

+312
-215
lines changed

css-pseudo/Overview.bs

Lines changed: 126 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TR: http://www.w3.org/TR/css-pseudo-4/
1010
Editor: fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
1111
Editor: Alan Stearns, Adobe Systems Inc., stearns@adobe.com
1212
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
1414
</pre>
1515

1616
<h2 id="intro">Introduction</h2>
@@ -36,11 +36,14 @@ Ignored Terms: typographic letter unit, Unicode general category
3636
and on their syntax and interaction with other <i>selectors</i>,
3737
see [[!SELECTORS4]].
3838

39+
<h2 id="typographic-pseudos">
40+
Typographic Pseudo-elements</h2>
41+
3942
<h3 id="first-line-pseudo">
4043
The ::first-line pseudo-element</h3>
4144

4245
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>.
4447

4548
<div class="example">
4649
The rule below means
@@ -125,7 +128,7 @@ The ::first-line pseudo-element</h3>
125128
</div>
126129

127130
<h4 id="first-text-line">
128-
The first formatted line</h4>
131+
Finding the First Formatted Line</h4>
129132

130133
In CSS, the ''::first-line'' pseudo-element
131134
can only have an effect when attached to a <i>block container</i>.
@@ -169,6 +172,9 @@ The first formatted line</h4>
169172
</pre>
170173
</div>
171174

175+
<h4 id="first-line-styling">
176+
Styling the First Line Pseudo-element</h4>
177+
172178
The ''::first-line'' pseudo-element’s generated box
173179
behaves similar to that of an inline-level element, but with certain restrictions.
174180
The following CSS properties apply to a ''::first-line'' pseudo-element:
@@ -184,6 +190,9 @@ The first formatted line</h4>
184190
</ul>
185191
User agents may apply other properties as well.
186192

193+
<h4 id="first-line-inheritance">
194+
Inheritance and the ''::first-line'' Pseudo-element</h4>
195+
187196
During CSS inheritance, the portion of a child element that occurs on the first line
188197
only inherits properties applicable to the ''::first-line'' pseudo-element
189198
from the ''::first-line'' pseudo-element.
@@ -195,88 +204,67 @@ The first formatted line</h4>
195204
<h3 id="first-letter-pseudo">
196205
The ::first-letter pseudo-element</h3>
197206

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>,
200210
if it is not preceded by any other content
201211
(such as images or inline tables) on its line.
202212
The ''::first-letter'' pseudo-element can be used
203213
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]])
206226
that precedes or follows the first <i>typographic letter unit</i> must also be included
207227
in the ''::first-letter'' pseudo-element.
208228

209229
<div class="figure">
210230
<img alt="Quotes that precede the first letter should be included." src="http://www.w3.org/TR/selectors/first-letter2.png">
211231
</div>
212232

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.
218235
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.
224238
In Dutch, for example, if the letter combination "ij" appears at the beginning of an element,
225239
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?
226244

227-
If the letters that would form the ''::first-letter''
228-
are not in the same element,
229-
such as "‘T" in <code>&lt;p&gt;'&lt;em&gt;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>&lt;p&gt;'&lt;em&gt;T...</code>,
230250
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
234253
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-
&lt;P&gt;Some text that ends up on two lines&lt;/P&gt;
250-
</pre>
254+
then the user agent need not create the pseudo-element(s).
251255

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-
&lt;P&gt;
256-
&lt;P::first-line&gt;
257-
&lt;P::first-letter&gt;
258-
S
259-
&lt;/P::first-letter&gt;ome text that
260-
&lt;/P::first-line&gt;
261-
ends up on two lines
262-
&lt;/P&gt;
263-
</pre>
256+
The ''::first-letter'' pseudo-element is contained within any ''::first-line''
257+
pseudo-elements, and thus inherits from ''::first-line''.
264258

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>
269261

270262
The first letter must occur on the <i>first formatted line</i>.
271263
For example, in this HTML fragment: <code>&lt;p&gt;&lt;br&gt;First...</code>
272264
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.
275266
In particular, it does not match the “F” of “First”.
276267

277-
<h4 id="application-in-css">
278-
Application in CSS</h4>
279-
280268
In CSS, the ''::first-letter'' pseudo-element
281269
only applies to block containers.
282270
<span class="note">A future version of this specification
@@ -323,6 +311,9 @@ Application in CSS</h4>
323311
selector ''p::first-letter'' matches the "N" of "Note".
324312
</div>
325313

314+
<h4 id="first-letter-styling">
315+
Styling the ''::first-letter'' Pseudo-element</h4>
316+
326317
In CSS a ::first-letter pseudo-element is similar to an inline-level element
327318
if its 'float' property is ''none'';
328319
otherwise, it is similar to a floated element.
@@ -424,26 +415,81 @@ Application in CSS</h4>
424415
approximate font sizes, for example to align baselines. Also, the glyph
425416
outline may be taken into account when formatting.
426417

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>&lt;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>&lt;p></code>,
449+
it will participate in <code>&lt;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+
&lt;P&gt;Some text that ends up on two lines&lt;/P&gt;
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+
&lt;P&gt;
484+
&lt;P::first-line&gt;
485+
&lt;P::first-letter&gt;
486+
S
487+
&lt;/P::first-letter&gt;ome text that
488+
&lt;/P::first-line&gt;
489+
ends up on two lines
490+
&lt;/P&gt;
491+
</pre>
492+
</div>
447493

448494
<h2 id="cssom">
449495
Additions to the CSS Object Model</h2>

0 commit comments

Comments
 (0)