diff --git a/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt b/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt new file mode 100644 index 0000000000..b60df89a3e --- /dev/null +++ b/Tests/LibWeb/Layout/expected/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.txt @@ -0,0 +1,4 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x0 children: not-inline + BlockContainer at (8,8) content-size 0x0 positioned children: not-inline + BlockContainer at (9,9) content-size 0x0 positioned children: not-inline diff --git a/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html b/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html new file mode 100644 index 0000000000..a8decc04b0 --- /dev/null +++ b/Tests/LibWeb/Layout/input/automatic-width-of-non-replaced-abspos-element-must-not-be-negative.html @@ -0,0 +1,11 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 727973afd2..f3126525a3 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -515,7 +515,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele }; auto solve_for_width = [&] { - return CSS::Length::make_px(width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box)); + return CSS::Length::make_px(max(CSSPixels(0), width_of_containing_block - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left - padding_right - border_right - margin_right.to_px(box) - right.to_px(box))); }; auto solve_for_right = [&] {