Re: pseudoclass based on document content

Justin Watt wrote:
> 
> That would work...
> 
> ...unless you're already specifying a uniform style for the TDs:
> 
> <td class="financial">123</td>
> <td class="financial">-123</td>
> <td class="financial">(none)</td>
> 
> Assuming the numbers and table are being generated by code, I'd
> could avoid the CLASS conflict this way:
> 
> <td class="financial" STYLE="color:black;">123</td>
> <td class="financial" STYLE="color:red;">-123</td>
> <td class="financial" STYLE="color:black;">(none)</td>
> 
> But then we've just totally blown a hole through the wall separating
> content/programming and style.


I think what you really want here is something like the proposed <nr/>
element in XHTML2 [1] if it had the ability to markup whether a number
was positive or negative, but for now, there's no reason (except for IE)
that you can't, as Andrew and Fantasai suggested, just use a space
separate list of classes in the table cell and loose the superfluous
style attribute element.

   It could certainly be argued that using a minus sign, or surrounding
the number in parentheses, or both is a matter of styling since all are
used are used to represent negative numbers.  Although, usually a
document will only use one format, so it could also be argued that it's
just a matter of marking up correct content.

Also, there is the ':contains' [2] pseudo class that may be able to be used.
eg. .financial:contains("-") { colour: red; }

[1] 
http://www.w3.org/TR/2003/WD-xhtml2-20030506/mod-inline-text.html#s_inline-textmodule_issue_1
[2] http://www.w3.org/TR/css3-selectors/#content-selectors
-- 
Lachlan Hunt

http://www.lachy.id.au/
lachlan.hunt@lachy.id.au

Received on Friday, 16 July 2004 23:39:17 UTC