diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 554d331e7c..205aeb7734 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -345,11 +345,12 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(L // whose bottom margin edge is below the element's bottom content edge, // then the height is increased to include those edges. for (auto* floating_box : state.get(root).floating_descendants()) { - auto const& floating_box_state = state.get(*floating_box); - float floating_box_bottom = floating_box_state.offset.y() + floating_box_state.content_height() + floating_box_state.margin_box_bottom(); - - if (!bottom.has_value() || floating_box_bottom > bottom.value()) - bottom = floating_box_bottom; + // NOTE: Floating box coordinates are relative to their own containing block, + // which may or may not be the BFC root. + auto margin_box = margin_box_rect_in_ancestor_coordinate_space(*floating_box, root, state); + float floating_box_bottom_margin_edge = margin_box.bottom() + 1; + if (!bottom.has_value() || floating_box_bottom_margin_edge > bottom.value()) + bottom = floating_box_bottom_margin_edge; } return max(0.0f, bottom.value_or(0) - top.value_or(0));