Selecting text within an element in CSS
An interesting discussion (which established itself as a branch from discussing behavioral characteristics of overflow
) is currently taking place on www-style regarding a text selector control. Much of the detail is still being fleshed out, but I thought I’d give a quick overview.
Initially discussed as a possible way to remove suppress whitespace textnodes between inline-block
s, the control itself would take the form of a pseudo element incorporating function notation taking a matching pattern as an argument – something along the lines of ::text(matching-pattern)
– which would have the ability to match strings of text within an element.
In contrast to my own confused ramblings (which I subsequently retracted), the consensus now is that the pseudo element should be excluded from crossing element boundaries in order to match a constituent of the argument, which means the full range of CSS layout properties can be exposed to the pseudo element (dependant on DOM-based pattern matching). Otherwise, consider Tab’s example:
p::text("foo b"){ display:block; }
<p>foo <span>bar</span> baz</p>
The above would split the pseudo element in two, since part of it would cross into the <span>
in order to match the pattern given as the argument, resulting in:
<p><text match="foo b">foo </text><i><text match="foo b">b</text>ar</i> baz</p>
Not only would this be quite-rightly unintuitive from an author’s perspective, but it would also be harder to implement (compared to excluding element boundary crossing) from a vendor point of view. Having said that, the former issue could be solved by providing a limited range of CSS properties, similar to that of ::first-line
, although conversation is veering away from such a resolution.
The sub-topic of discussion at the moment is how to avoid one ::text() boundary from crossing another.
If you can take some time out of your day, it’s certainly an interesting read.
Comments are closed.