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

pseudoclass based on document content

From: Justin Watt <jwatt@email.unc.edu>
Date: Fri, 16 Jul 2004 17:40:00 -0400 (EDT)
To: www-style@w3.org
Message-ID: <Pine.A41.4.44+UNC.0407161605100.39586-100000@login8.isis.unc.edu>

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
Received on Friday, 16 July 2004 17:42:36 UTC

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