aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/layout/engine.nim16
-rw-r--r--test/layout/absolute-before-resolved-margins.expected5
-rw-r--r--test/layout/absolute-before-resolved-margins.html10
3 files changed, 25 insertions, 6 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 6ced24bb..b3500e9a 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -2569,12 +2569,16 @@ proc layoutBlockChildren(state: var BlockState; bctx: var BlockContext;
# Delay this block's layout until its parent's dimensions are
# actually known.
var offset = state.offset
- # I *think* this is right, because we want to freeze the box at
- # the layout's current position. So even if a next child increased
- # the margin todo, that should not change the absolute block's
- # position.
- #TODO but I'm not sure if this is really what the standard says...
- offset.y += bctx.marginTodo.sum()
+ # We want to get the child to a Y position where it would have
+ # been placed had it not been absolutely positioned.
+ #
+ # Like with floats, we must consider both the case where the
+ # parent's position is resolved, and the case where it isn't.
+ # Here our job is much easier in the unresolved case, because
+ # subsequent children's layout doesn't depend on our position;
+ # so we can just defer margin resolution to the parent.
+ if bctx.marginTarget != state.initialMarginTarget:
+ offset.y += bctx.marginTodo.sum()
bctx.lctx.queueAbsolute(child, offset)
continue
if child.computed.establishesBFC():
diff --git a/test/layout/absolute-before-resolved-margins.expected b/test/layout/absolute-before-resolved-margins.expected
new file mode 100644
index 00000000..706ef4cf
--- /dev/null
+++ b/test/layout/absolute-before-resolved-margins.expected
@@ -0,0 +1,5 @@
+
+
+absolute 2em
+
+absolute 2
diff --git a/test/layout/absolute-before-resolved-margins.html b/test/layout/absolute-before-resolved-margins.html
new file mode 100644
index 00000000..29cddc03
--- /dev/null
+++ b/test/layout/absolute-before-resolved-margins.html
@@ -0,0 +1,10 @@
+<div style="margin-top: 1em">
+<div style="position: absolute">
+absolute
+</div>
+<div style="margin-top: 2em; margin-left: 10ch; margin-bottom: 1em">
+2em
+</div>
+<div style="position: absolute">
+absolute 2
+</div>