W3C home > Mailing lists > Public > www-style@w3.org > February 2007

[CSS21] valid values with "rgb()"

From: Del Merritt <del@alum.mit.edu>
Date: Mon, 26 Feb 2007 16:50:00 -0500
Message-ID: <45E35608.4080507@alum.mit.edu>
To: www-style@w3.org

I am puzzling over what the valid values are for the "rgb()" function. 

Take, for example, a CSS stylesheet with these declarations:

    p {color: green;}
    span {color: rgb( 0, 255, 0);}
    span {color: rgb(100%, 0, 0);}

And then assume the styling is applied to a valid [X]HTML document that 
includes this:

    <p>This sentence <span>must</span> be green.</p>

How should this be rendered?  Opera 9.0 (under Linux) renders the 
sentence as green, except that the word "must" is in red, while FireFox 
2.0.0.2 renders the word "must" in "lime" (#0f0).

While it is true that you aren't supposed to mix percentages and 
integers, "0" has long had a special place in CSS.  "0" is (or may be) 
unit-less most places you find it.  In Lie&Bos's /Cascading Style 
Sheets, second edition/, the chapter on color specification clearly 
allows (and in fact uses as an example) the "rgb(100%,0,0)" notation. 
(see pp. 226-228.) 

Unfortunately, the CSS spec:

    http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#color-units

doesn't use an explicit "MUST" or a "SHALL":

    The format of an RGB value in the functional notation is 'rgb('
    followed by a comma-separated list of three numerical values (either
    three integer values or three percentage values) followed by ')'.
    The integer value 255 corresponds to 100%, and to F or FF in the
    hexadecimal notation: rgb(255,255,255) = rgb(100%,100%,100%) = #FFF.
    Whitespace characters are allowed around the numerical values.

Instead, the subsequent examples show all-integer or all-percentage 
values.  That Lie&Bos would get this "wrong" suggests an issue with the 
spec.  (Or was there a spec change subsequent to the book's 
publication?  Unfortunately I don't currently have a copy of the third 
edition nor access to the second edition's eratta.)

It's also worth noting that the section on "Percentages" earlier in the 
spec (4.3.3) uses them in the context of size.  "Percentage values are 
always relative to another value, for example a length."  But while 
sizes are relative to the containing box, color percentages are always 
relative to the integer values ranging from 0 to 255.  So it seems to me 
that there would be some wiggle room for allowing a mix of color value 
representations in the rgb() function, even if it only applies to "0".

Is there clarification of this in the CSS3 spec?  If so, where?

Thanks,
-Del
Received on Monday, 26 February 2007 21:50:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:49 GMT