Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Getting table margin values fails in Firefox   Message List  
Reply | Forward Message #28491 of 52285 |
Re: [ydn-javascript] Getting table margin values fails in Firefox

dunphey wrote:
> Below is an example of getStyle attempting to access the left margin
> value of a table. It fails in firefox. Oddly, I can obtain the value
> by cloning the table.
>
> Does anyone have an understanding of what's going on here---why the
> clone would work?
>
> http://work.octoberblue.com/sandbox/getstyle
>
>
Hi dunphey,


This is a Firefox 2 issue, likely related to the following bugs:
https://bugzilla.mozilla.org/show_bug.cgi?id=381328
https://bugzilla.mozilla.org/show_bug.cgi?id=200089

This appears to be fixed in Firefox 3b4.

The clone works because it is not yet attached to the page. You'll see
the same result when creating a table dynamically:

<style type="text/css">
table {
margin:50px;
}
</style>

<script type="text/javascript">
var node = document.createElement('table');
alert(getComputedStyle(node, '').marginLeft);

document.body.appendChild(node);
alert(getComputedStyle(node, '').marginLeft);
</script>


Opera 9 and Safari 3 agree that the node has no marginLeft (marginLeft
=== "") applied before appending and '50px' after, while FF 2 reports
'50px' before appending and '0px' after. FF3b4 reports '50px' in both
cases.

I did some testing, and it seems that in general Opera and Safari do not
compute values for elements not appended to the tree, while FF does.

Regarding the correct behavior for unappended elements, per the CSS 2.1
spec:

<q cite
"http://www.w3.org/TR/1998/REC-CSS2-19980512/cascade.html#computed-value">
Once a user agent has parsed a document and constructed a document tree,
it must assign, for every element in the tree, a value to every property
that applies to the target media type.
...
User agents must first assign a specified value to a property based on
the following mechanisms (in order of precedence):
1. If the cascade results in a value, use it.
2. Otherwise, if the property is inherited, use the value of the parent
element, generally the computed value.
3. Otherwise use the property's initial value. The initial value of each
property is indicated in the property's definition.

Since it has no parent, the root of the document tree cannot use values
from the parent element; in this case, the initial value is used if
necessary.
</q>

This implies that elements outside of the document tree are not required
to have values assigned ("it must assign, for every element in the
tree"), meaning that technically both implementations are correct.
Perhaps some clarification is needed here for the sake of x-browser
consistency.

Matt



Wed Apr 2, 2008 1:17 am

matt.sweeney
Offline Offline
Send Email Send Email

Forward
Message #28491 of 52285 |
Expand Messages Author Sort by Date

Below is an example of getStyle attempting to access the left margin value of a table. It fails in firefox. Oddly, I can obtain the value by cloning the table....
dunphey
Offline Send Email
Apr 1, 2008
1:56 am

For the records sake, I've blogged about this bug. http://octoberblue.com/firefox-getcomputedstyle-table-margin-bug/ RD...
dunphey
Offline Send Email
Apr 2, 2008
1:02 am

... Hi dunphey, This is a Firefox 2 issue, likely related to the following bugs: https://bugzilla.mozilla.org/show_bug.cgi?id=381328 ...
Matt Sweeney
matt.sweeney
Offline Send Email
Apr 2, 2008
2:04 am

Matt, Great insight and exactly the response I was hoping for. Thanks so much! (I update my blog post to reflect your findings.) Ryan...
dunphey
Offline Send Email
Apr 2, 2008
5:41 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help