getComputedStyle() behavior

I have a question about computed style property values.

For a non-positioned, non-replaced element that does not have explicit 
dimensions set and is laid  out according to normal flow, what should be 
returned for the value of 'top', 'right', 'bottom', or 'left' by the 
getPropertyValue() method of the DOM CSS 'CSSStyleDeclaration' interface (e.g.
 

getComputedStyle( document.getElementById( 'homeLink' ), null ).
getPropertyValue( 'left' ) 

)?

I'd like to think that it would return an actual value that specifies the 
element's offset with respect to the containing block, but from reading the 
specs I'm not sure what I should expect to get back. 

I'm currently experimenting with this in Netscape 6.1, and in the scenario 
I've described, Netscape returns an actual value in pixels for 'left', ... 
though I don't know on what basis it is determining the point of reference 
for the offset... 

Please see my example page for reference at 
http://www.jmmcc.com/public/W3C/absp4.html 
(as far as I know this will only work in Netscape 6, it definitely does not 
work in IE 5 PC). 

As you can see, the purple element is absolutely positioned and the yellow 
element is absolutely positioned within that.  Within the yellow element 
there are green inline elements with varying amounts of text content, laid 
out according to normal flow (the text is just filler lifted from the ever 
popular MSN.com). 

The idea in this scenario is to have an arbitrary number of green elements, 
each with a corresponding menu of links that will be left aligned with and 
below the green element and can appear and disappear.  The only way that I 
can see to set up a system like this is if you can retrieve an actual value 
for 'left', ... in pixels for the green elements, then use absolute 
positioning to place the corresponding menus below them -- which is what I've 
done.  For the green elements, Netscape returns the offset in pixels from the 
border edge of the purple element (which is not the containing block for the 
green elements) to the border edge of the green element.  Mouseover the green 
elements to see a menu appear below (currently only "MSN Home" and "Search"). 

So there are a couple of questions here:

1) See the second paragraph -- "For a non-positioned...".  In the CSS 2 spec 
it says the properties 'left', ... apply to positioned elements, and these 
(the green elements) aren't positioned -- I just want to find out where they 
end up. 

2) If a value should be returned, how should that value be determined (e.g., 
with respect to the containing block)? 

3) It's really covered by the answers to the first two questions, but just to 
put it in perspective, should Netscape's implementation be considered 
conforming, and if so, should the behavior exhibited by Netscape be relied 
upon, that is can it be considered the definitive conforming behavior in this 
scenario (I doubt it)? 

I think perhaps this is something Netscape cooked up and is not conforming to 
the DOM CSS spec, but is perhaps more useful: see this bugzilla bug that was 
mentioned in another thread: http://bugzilla.mozilla.org/show_bug.cgi?
id=32169 , 
 especially Additional Comment #8 From Johnny Stenback.  As mentioned in the 
 bugzilla thread, the 'ViewCSS' interface part of the DOM CSS spec says that 
 "The CSSStyleDeclaration is read-only and contains only absolute values."  
 Absolute values does not include pixel values, so I doubt that that statment 
 really means what it says because that would be a very useless method where 
 you would expect to find a useful method, and there is no mention of "only 
 absolute values" in the 'CSSStyleDeclaration' interface part of the spec.  
 And of course, as also mentioned in the bugzilla thread, you wouldn't want 
 the computed value anyway, you would want the actual value (at least, I 
 would), but 'CSSStyleDeclaration' is defined as providing access to the 
 computed value (really a moot point if it's returning a pixel value though). 


P.S. A few things you should know about the example:

Never mind the flickering of the menus, it seems to be some Netscape bug.

I only calculate the value to use for the absolute positioning of the menu 
once when the document loads, so if the canvas is resized the menu may not be 
aligned with its green element anymore. 

The routine isn't quite worked out -- the menus are a little sticky, but I 
ask you to concentrate on the question at hand. 

Thanks,
Jesse

Received on Sunday, 9 December 2001 16:11:27 UTC