Loading ...
Sorry, an error occurred while loading the content.

Getting table margin values fails in Firefox

Expand Messages
  • dunphey
    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.
    Message 1 of 4 , Mar 31 6:56 PM
    • 0 Attachment
      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
    • dunphey
      For the records sake, I ve blogged about this bug. http://octoberblue.com/firefox-getcomputedstyle-table-margin-bug/ RD
      Message 2 of 4 , Apr 1, 2008
      • 0 Attachment
        For the records sake, I've blogged about this bug.

        http://octoberblue.com/firefox-getcomputedstyle-table-margin-bug/

        RD

        --- In ydn-javascript@yahoogroups.com, "dunphey" <ryan@...> 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
        >
      • Matt Sweeney
        ... Hi dunphey, This is a Firefox 2 issue, likely related to the following bugs: https://bugzilla.mozilla.org/show_bug.cgi?id=381328
        Message 3 of 4 , Apr 1, 2008
        • 0 Attachment
          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
        • dunphey
          Matt, Great insight and exactly the response I was hoping for. Thanks so much! (I update my blog post to reflect your findings.) Ryan
          Message 4 of 4 , Apr 2, 2008
          • 0 Attachment
            Matt,

            Great insight and exactly the response I was hoping for. Thanks so much!

            (I update my blog post to reflect your findings.)

            Ryan
          Your message has been successfully submitted and would be delivered to recipients shortly.