Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 4560b9e828c6a01e9d06a5072e7be4df34891ae0
      
https://github.com/WebKit/WebKit/commit/4560b9e828c6a01e9d06a5072e7be4df34891ae0
  Author: Alan Baradlay <[email protected]>
  Date:   2026-04-15 (Wed, 15 Apr 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/positioning/relpos-percentage-offset-anonymous-block-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/positioning/relpos-percentage-offset-anonymous-block.html
    M Source/WebCore/rendering/RenderBoxModelObject.cpp

  Log Message:
  -----------
  Element Position is incorrect with regards to the ancestor box
https://bugs.webkit.org/show_bug.cgi?id=9774
<rdar://problem/96548847>

Reviewed by Antti Koivisto.

Given:

  <div style="height: 500px">
      <span style="position: relative; top: -5%"><img></span>
      <div></div>
  </div>

The image should be shifted up by 25px (5% of the 500px container).
Instead it stays at its normal position -- the percentage is ignored.

The sibling <div> is the trigger. Without it, the span sits directly
inside the 500px container and the offset works. With the sibling,
the render tree wraps the inline content in an anonymous block:

  container (500px)
      anonymous block (auto height)
          span (position: relative, top: -5%)
              img
      div

relativePositionOffset() resolves percentage top against the
containing block's height. The containing block for the span is the
anonymous block, which has auto height. Percentage offsets against
auto height resolve to 0, so the offset is lost.

Anonymous blocks are a render tree implementation detail -- the
author never created one. The fix skips them when looking up the
containing block for relative position offset resolution, so the
percentage resolves against the authored container (500px) instead.

This is a workaround until anonymous block construction is avoided
entirely (webkit.org/b/307004).

* 
LayoutTests/imported/w3c/web-platform-tests/css/CSS2/positioning/relpos-percentage-offset-anonymous-block.html:
 Added.
* Source/WebCore/rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::relativePositionOffset):

Canonical link: https://commits.webkit.org/311275@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to