We have pseudo-elements ::first-letter and ::first-line and this is all we can use to select specific parts of text. Hereby I propose a full set of pseudo-elements akin to the child selector pseudo-classes.
-
::first-word
-
::first-sentence
-
::nth-letter(an+b)
-
::nth-word(an+b)
-
::nth-line(an+b)
-
::nth-sentence(an+b)
-
::last-letter
-
::last-word
-
::last-line
-
::last-sentence
-
::last-nth-letter
-
::last-nth-word
-
::last-nth-line
-
::last-nth-sentence
-
::each-word
-
::each-line
-
::each-sentence
-
::only-letter
-
::only-word
-
::only-line
-
::only-sentence
and combinations thereof:
- ::nth-word(an+b)::first-letter
- ::nth-word(an+b)::nth-letter(an+b)
- ::nth-word(an+b)::last-letter
- ::only-sentence::last-letter and so on.
Practical examples:
Make the first word of each paragraph uppercase:
p::first-word { text-transform: uppercase; }
Make the first word of each sentence uppercase:
p::each-sentence::first-word { text-transform: uppercase; }
This is especially useful for Georgian text where capitalization is applied to whole words and not to the first letter of a word like in Western text.
Bustrophedon text:
p::nth-line(2n+2) { direction: rtl; }