at (8,8) content-size 100x100 floating [BFC] children: inline
+ line 0 width: 26.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 3, rect: [8,8 26.640625x17.46875]
+ "top"
+ TextNode <#text>
+ BlockContainer
at (8,108) content-size 100x100 floating [BFC] children: inline
+ line 0 width: 26.25, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 4, rect: [8,108 26.25x17.46875]
+ "left"
+ TextNode <#text>
+ BlockContainer
at (208,108) content-size 100x100 floating [BFC] children: inline
+ line 0 width: 37.109375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 5, rect: [208,108 37.109375x17.46875]
+ "right"
+ TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+ PaintableWithLines (BlockContainer) [0,0 800x208]
+ PaintableWithLines (BlockContainer) [8,8 600x0] overflow: [8,8 300x200]
+ PaintableWithLines (BlockContainer
#top) [8,8 100x100]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
#left) [8,108 100x100]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
#right) [208,108 100x100]
+ TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html b/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html
new file mode 100644
index 0000000000..8244ca53d9
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/floats-with-negative-percentage-margins.html
@@ -0,0 +1,22 @@
+
top
left
right
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index fecaf1abe7..432ebf3138 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -962,7 +962,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
CSSPixels tentative_offset_from_edge = 0;
bool fits_next_to_preceding_float = false;
if (side == FloatSide::Left) {
- tentative_offset_from_edge = preceding_float.offset_from_edge + preceding_float_state.content_width() + preceding_float_state.margin_box_right() + box_state.margin_box_left();
+ tentative_offset_from_edge = max(preceding_float.offset_from_edge + preceding_float_state.content_width() + preceding_float_state.margin_box_right(), 0) + box_state.margin_box_left();
if (available_space.width.is_definite()) {
fits_next_to_preceding_float = (tentative_offset_from_edge + box_state.content_width() + box_state.margin_box_right()) <= available_space.width.to_px_or_zero();
} else if (available_space.width.is_max_content() || available_space.width.is_indefinite()) {