Skip to content

Vertical margin for position=fixed elements is missing #7035

Closed

Description

@frewsxcv

Relevant to #782

Code

<html>
  <head>
    <style>
    .container {
      display: block;
    }
    #fixed {
      background: green;
      position: fixed;
      height: 10px;
      width: 10px;
    }
    </style>
  </head>
  <body>
    <div class="container">
      <div id="fixed"></div>
    </div>
    <script>
      var element = document.getElementById("fixed");
      console.log(element.getBoundingClientRect().top);
      console.log(element.getBoundingClientRect().bottom);
    </script>
  </body>
</html>

Gecko

screen shot 2015-08-06 at 9 55 36 am

Log

8
18

Servo

screen shot 2015-08-06 at 9 55 45 am

Log

0
10

Activity

  1. added
    I-wrong
    on Aug 6, 2015
  2. frewsxcv commented on Aug 11, 2015

    @frewsxcv
    ContributorAuthor

    I am (attempting) to figure this out

  3. added
    C-assigned
    on Aug 11, 2015
  4. pcwalton commented on Aug 11, 2015

    @pcwalton
    Contributor

    The problem here is likely either that the hypothetical box is wrong or that we aren't taking it into account for position:fixed. You can see which one it is by changing to position:absolute and seeing if the bug persists.

    For more info, search for "hypothetical box" in the CSS 2.1 spec.

  5. frewsxcv commented on Aug 11, 2015

    @frewsxcv
    ContributorAuthor

    Bug persists with absolute, so I assume the hypothetical box is wrong

  6. frewsxcv commented on Aug 11, 2015

    @frewsxcv
    ContributorAuthor

    With respect to the colored box, should all the values for its fragment.margin be 0? I assume so, just double checking

    The answer to my question is 'yes'

  7. frewsxcv commented on Aug 12, 2015

    @frewsxcv
    ContributorAuthor

    Okay, I have been at this long enough. I guess take a break from it and hopefully it is on the right track.

    By definition, "hypothetical box" for the green square should be at 8px,8px because that is where it would be placed if it were static.

    One potential problem is the parent Fragment (presumably for <body>) of the green square's Fragmenthas its vertical margin collapsed (I think), so its box position is at 0px. If the green square is position=static, the parent Fragment has box position at 8px.

    So right now, my best guesses. Either:

    1. Somethings is wrong with the collapsed margin algorithm and the margin of the <body> fragment should have collapsed (relevant areas of code: here and here)
    2. Something needs to happen here to set the start position for the green square lower to counter the collapsed vertical margins

    If anyone has hints/tips, let me know

  8. removed
    C-assigned
    on Aug 26, 2015
  9. mrobinson commented on Nov 5, 2015

    @mrobinson
    Member

    I attempted to fix this bug last year in https://github.com/mrobinson/servo/tree/margin-collapse, but couldn't manage to do it without introducing other regressions. Perhaps my half-done work will be useful for fixing this.

  10. mrobinson commented on Nov 5, 2015

    @mrobinson
    Member

    I think this describes the bug:

    When an absolutely positioned element has a static position in an
    element with margins collapsed-through, the CSS spec says its position
    should be defined by top margin (and not the collapsed top and bottom
    margin) of the outermost collapsed-through ancestor.
    
  11. eefriedman commented on Nov 5, 2015

    @eefriedman
    Contributor

    Yes, that looks right.

  12. nox commented on Sep 30, 2017

    @nox
    Contributor

    This was fixed.

  13. mrobinson commented on Sep 30, 2017

    @mrobinson
    Member

    @nox Do you know what PR fixed this issue or dd you just notice that the test case is working now?

  14. nox commented on Sep 30, 2017

    @nox
    Contributor

    The latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/blockI-wrong

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions