[whatwg] New method for obtaining a CSS property
brettz9 at yahoo.com
Thu Jan 27 22:37:09 PST 2011
On 1/28/2011 2:22 AM, Boris Zbarsky wrote:
> On 1/27/11 4:48 AM, Brett Zamir wrote:
>> I was thinking of it grabbing the "winning" property for the whole
>> document, i.e., the one which would be applicable without knowing more
>> contextual information. So, if the selector specified were ".error", it
>> wouldn't get "div.error"
> That's pretty difficult to define, actually. Should it get
As mentioned in my other response just now, no, I don't think it should.
The idea is to be as literal as possible, following a predictable path
(e.g., the very first or maybe very last reference). It couldn't and
wouldn't need to follow CSS cascading behavior, since the purpose here
is different. It would generally be expected that there would only be
one match since the designer and developer would coordinate to find a
As with regular contextual CSS, one needs to be careful not to overwrite
one's own rules, but this use case is treating selector-property
associations as (read-only) variables rather than contextually resolved
Still, it could also be made to follow cascading behavior (e.g.,
!important getting higher precedence). As long as it was predictable,
the point is for there to be a clear way to figure it out.
>> Whatever the rules, it would be the team's responsibility to ensure it
>> was unique enough to provide the right value (as it is within CSS itself
>> via cascading).
> Why is just asking for computed style, and getting correct answers
> that include the results of the cascade, not the right solution here?
Sure, one could pick an arbitrary element, and hope it didn't have its
own style attribute, or again, make a pseudo document, but this does not
seem as satisfying as just querying the stylesheets, as one can do--but
only by an extra utility function--in iterating through
document.stylesheets. Best practice should not require hacks, in my
opinion. One should be able to just tell people, if you want to grab a
use this simple method to do so.
More information about the whatwg