Re: [css-selectors] :contains()

(12/04/17 21:06), Sebastian Zartner wrote:
> Possible use cases for :contains() are:
> - styling negative numbers (https://bugzil.la/221981#c30)

So this is :contains("-").

> - highlighting Sundays in a calendar

How so? I can't think of a way how this works. Note that in a normal
calender, there's no text like "SUN" in each cell.

> - highlighting search matches in a table

Can you elaborate on this? Do you mean something similar to the color
for "Yes" and "No" in a Wiki-style comparison table like[1]? At first
glance, td:contains("Yes") and td:contains("No") do look interesting as
this can indeed achieve some sort of content-style separation (for
example, there's discussions about these styles in the Talk page[2] of
the {{Yes}} template, and the concluded style could have been applied as
CSS rules instead of change to the template), but this is rather
restricted because it turns out that there are all sorts of text strings
that use the {{Yes}} style.

> - hiding parts of a page (https://bugzil.la/221981#c4)

I have the feeling that this use is very fragile, and it's no more
useful than @docuement. It would be nice if someone working on Add
blockers can share some experiences here.

(12/04/19 19:07), Sebastian Zartner wrote:
>> Currently text nodes are one of the only parts of the DOM not matchable 
>> by CSS selectors, but there is no reason to make :contains 
>> computationally expensive by allowing it to match innerText. If it only 
>> matched direct text-nodes it would still be useful for the listed 
>> examples but much faster.

I don't quite understand the second and third use cases listed above,
but for the first and the fourth that's indeed the case.

> I assume you mean the 'textContent' property.
> This would be a speed boost in many cases, though you would also lose functionality. E.g. imagine something like this:
> 
> <p>This is an <strong>important</strong> sentence.</p>
> 
> Then you wouldn't have the possibility to style the paragraph by searching for the word 'important'.

I think if you can provide a pointer to a site that does something like
this, it would be helpful. (Having said that, it is indeed quite
unnatural if :contain() means "directly contain".)

> That's why I mentioned it. There will be cases, in which you need to >
do more than a simple substring check. E.g. somebody might want to
> highlight a table row depending on whether it contains an email
> address.

Same here.

[1]
http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28Cascading_Style_Sheets%29#Grammar_and_rules
[2] http://en.wikipedia.org/wiki/Template_talk:Yes



Cheers,
Kenny

Received on Thursday, 19 April 2012 15:20:29 UTC