13.07.2011 23:24, Maujor (via-gmail) wrote:
CSS:
p::first-letter { color: red; }
The pseudo-element has widespread support (though I'm not that sure of
the notation with "::" instead of the original ":") but with many bugs -
see e.g.
http://www.webdevout.net/browser-support-css#css2pseudoelements
for some notes on bugs in older browsers.
HTML:
<p>— Paragraph</p>
<p>© Paragraph</p>
By the CSS 2.1 specification, the styling should be applied to the
letter "P", because the dash and the copyright sign are not letters. The
© is historically based on the letter "C", but it is classified as a
Symbol in Unicode, not Letter.
It is not crystal clear what CSS 2.1 means by "letter" here, but the
most natural interpretation is that it is a character that has General
Category value that starts with "Letter", in Unicode. Note that
http://www.w3.org/TR/CSS2/selector.html#first-letter
defines "punctuation" in such terms, i.e. by referring to Unicode
General Category.
There are still open questions. What if the element starts with a letter
followed by a combining diacritic mark, e.g. <p>áfoo</p> or
<p>Ṕfoo</p>? Does the element refer to the first Unicode
character (code point), or the first text character? In the examples,
the acute accent ĭ is a separate Unicode character, but it is
rendered as part of a text character - a letter with a diacritic mark.
Firefox 4 interprets that the diacritic mark is part of the scope of
::first-letter, and this makes a lot of sense.
All latest browsers:
Firefox doesn't apply the CSS rule on both paragraphs;
Opera, Chrome and IE apply the CSS rule coloring — and ©
Safari on Windows apply coloring — and © plus P;
Safari gets it wrong. Otherwise, this depends on interpretation of the spec.
It seems that only Firefox is according the specs. Since ::first-letter
only apply to letters and digits.
The ::first-letter pseudo-element is defined as referring to the first
letter or digit (this is expressed a bit oddly, first mentioning letters
only, then only later digits), "if it is not preceded by any other
content (such as images or inline tables) on its line". This is somewhat
obscure: as the parenthetic remark does not mention other characters, we
might read this as saying that they don't affect but are skipped when
searching the first letter or digit. On the other hand, "any other
content" is a pretty strong expression.
But indepedently of this, the dash — is classified as a
punctuation character in Unicode, and the spec says:
"Punctuation (i.e, characters defined in Unicode [UNICODE] in the "open"
(Ps), "close" (Pe), "initial" (Pi). "final" (Pf) and "other" (Po)
punctuation classes), that precedes or follows the first letter should
be included"
followed by an image that illustrates how an opening quotation mark is
styled, too. It says "should", making things somewhat obscure
normatively, and it doesn't specify what "precedes" really means: may a
space intervene? How about _several_ punctuation marks, as in <p>[(a)]
foo</p>?
The em dash — is a punctuation mark but not in the subcategories
explicitly listed in the spec (but Pd = Punctuation, dash). The
copyright sign is not punctuation at all. So in both cases, the
situation depends on how we interpret "any other content". Either
nothing should be colored, or the "P" alone should be colored.
Firefox 4 seems to be relatively consistent: ::first-letter refers to
the first letter or digit, if there are no other characters before it,
otherwise to nothing, but if the letter or digit is _immediately_
preceded or followed by one or more punctuation characters, the
::first-letter pseudo-element refers to both the punctuation
character(s) and the letter or digit. (So an intervening space matters.)
IE 9 seems to have a liberal idea of a letter: it covers any character
that is not in the punctuation classes. Now that I really think about
it, maybe this too is a plausible interpretation. People often say
"letter" when they mean "character", and maybe the spec really means
that. This would explain why the clause "if it is not preceded by any
other content (such as images or inline tables) on its line" does not
mention characters! The first letter cannot be preceded by other
characters if "letter" really means "character"!
--
Yucca, http://www.cs.tut.fi/~jkorpela/
______________________________________________________________________
css-discuss [[email protected]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/