1

I am wondering if there are any other selectors which select only part of an HTML element. I know of these two:

:first-letter
:first-line

But AFAIK there are no other selectors which do this. I am interested in any (even browser-specific) selectors or other methods of manipulating only part of a block of text.

The Use Case

I have (more) control over the .css and .js than over the DOM. I've been using js workarounds but want to include any CSS solutions as well, because I don't like to depend of javascript for my styles.

Even if the solution is only supported in konquerer it is still better than nothing IMO.

jisaacstone
  • 4,234
  • 2
  • 25
  • 39

2 Answers2

4

Nope, those are the only two content pseudo-elements available that select real text nodes. Nothing new has made it into the CSS3 recommendation.

One of the proposals that didn't make it was ::selection (roughly implemented by Opera, Safari and Chrome, and by Firefox as ::moz-selection), but your use case doesn't really say anything about what you want to do so I have no idea if that selector is relevant to your needs.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • eh, I was hoping for something like `:nth-letter` or `:nth-line`. I know it was a long shot but really, why include those two if you won't take it to the logical conclusion? – jisaacstone Jul 21 '11 at 21:58
  • oh, and while i'm compiling a wish list a `:contains(text)` selector would be cool too :) – jisaacstone Jul 21 '11 at 21:59
  • @JIStone: Performance constraints, really. The first letter/line is pretty easy to calculate but anything beyond that makes things very complicated for rendering. Also, there *was* a `:contains()` pseudo-class as well, but it doesn't select the text, it selects the *element* that contains it. Like `::selection`, [it was dropped from the spec](http://stackoverflow.com/questions/4781141/why-h3nth-child1containsa-selector-doesnt-work/4781167#4781167), but unlike it, no browser supports it. – BoltClock Jul 21 '11 at 22:01
1

I'm not aware of any browser-specific pseudo-elements, but there are also the ::before and ::after pseudo-elements. See the CSS 2.1 specification from the W3C.

GarlicFries
  • 8,095
  • 5
  • 36
  • 53