Forum Moderators: not2easy
- John
Does not work...
span.capitalize:first-letter {
text-transform: uppercase;
}
W3C: 5.12.2 The :first-letter pseudo-element [w3.org]
The :first-letter pseudo-element must select the first letter of the first line of a block, if it is not preceded by any other content (such as images or inline tables) on its line....
as you found with the <p>,
:first-letter can only transform the first letter of a block-level element. 5.12.2 The :first-letter pseudo-element [w3.org]
The :first-letter pseudo-element must select the first letter of the first line of a block, if it is not preceded by any other content (such as images or inline tables) on its line.
It's this way because you could not realistically float a first letter if it's inside an inline element, which is nested in a block. Typically First letter effects make the first letter a lot larger, "drop caps" and these then are usually floated to make the rest of the sentence flow properly.
fictional example, using a span to emulate what would happen if it worked:
p.fl:first-letter, p span {float: left; font-size: 40px;}<p class="fl">First Letter</p>
<p>Emulated <span>F</span>irst Letter<p>
solution possibly depends on what is in the span, if it's more than one word and you do just want the first word to be capitalised you will probably need some javascript that can emulate sentence case if all words can be capitalised then simply putting
text-transform: capitalize; on the span would do sentence case via CSS, is not possible - to make it so would mean CSS would have to parse the text inside an element and have some sort of "knowledge" as to what constitutes the beginning/end of a sentence, and as the end is not always a full stop, nor is CSS a scripting language, I can't see it happening
[edited by: SuzyUK at 12:15 pm (utc) on Jan. 2, 2008]