W3C home > Mailing lists > Public > www-style@w3.org > July 2004

Re: pseudoclass based on document content

From: Justin Wood <jw6057@bacon.qcc.mass.edu>
Date: Sat, 17 Jul 2004 01:12:11 -0400
Message-ID: <40F8B52B.4040504@bacon.qcc.mass.edu>
To: W3C Style List <www-style@w3.org>

Justin Watt wrote:

>This might be something of a black hole, but has anyone thought about
>using pseudoclasses to apply style based on document content, as opposed
>to structure or other intrinsic qualities of structure?
>One example of what I mean is described here:
>Let's say you have a table that has negative numbers in it. You want the
>negative numbers to appear red while the other numbers inherit their
>The might be "pseudo"-coded in CSS as:
>TD:negative-number {color:red;}
>The problem is that variations in content are infinite. So it probably
>wouldn't make sense to create a ":negative-number" pseudoclass because 100
>different people would probably request 100 different selectors for their
>special cases.
>Maybe there is a way to take advantage of simple pattern matching based on
>content, perhaps using regular expressions?
>The following might read: make the text inside TDs red if that text begins
>with a hypen (minus-sign) and ends with one or more other characters.
>TD:content-regex(/-.+/) {color:red;}
>The benefit of this approach being that if negative numbers in your
>document are surrounded by parentheses, you can modify the regular
>expression in the stylesheet rather than having to modify your document to
>play nice with a UA's implementation of ":negative-number".
>Justin Watt
As a note, I like the *thought* of the reg-ex, however think of the CSS 
forward compat parsing rules, what would happen when a regex contains a 
) or a {, } etc. (insert other possible regex chars), even when escaped  
a UA that does not understand the :content-regex( ... )  as you propose 
would END parsing at the closing ).

so in light of "thought" it is good, but there would have to be a way to 
specify such characters without actually using them, which would make 
any worthwhile regex that much harder to write/parse and also make for 
real annoying author errors on the subject.

The rest of your issue which I would have stated has been responded to 
in the thread already, so I will keep from adding duplicate thought.

~Justin Wood
Received on Saturday, 17 July 2004 01:13:21 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:14 UTC