diff --git a/Tests/LibWeb/Layout/expected/flex-abspos-item-with-preceding-whitespace.txt b/Tests/LibWeb/Layout/expected/flex-abspos-item-with-preceding-whitespace.txt
new file mode 100644
index 0000000000..7fa013d846
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/flex-abspos-item-with-preceding-whitespace.txt
@@ -0,0 +1,7 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer at (1,1) content-size 798x20 children: not-inline
+ BlockContainer
at (10,10) content-size 780x2 children: not-inline
+ Box at (11,11) content-size 778x0 flex-container(row) children: not-inline
+ BlockContainer <(anonymous)> at (11,11) content-size 0x0 children: inline
+ TextNode <#text>
+ BlockContainer at (11,-39) content-size 100x100 positioned children: not-inline
diff --git a/Tests/LibWeb/Layout/input/flex-abspos-item-with-preceding-whitespace.html b/Tests/LibWeb/Layout/input/flex-abspos-item-with-preceding-whitespace.html
new file mode 100644
index 0000000000..a92bd052a1
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/flex-abspos-item-with-preceding-whitespace.html
@@ -0,0 +1,16 @@
+
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
index 4022652be4..e041c361bb 100644
--- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp
@@ -92,6 +92,8 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
bool is_out_of_flow = layout_node.is_absolutely_positioned() || layout_node.is_floating();
if (is_out_of_flow
+ && !layout_parent.display().is_flex_inside()
+ && !layout_parent.display().is_grid_inside()
&& layout_parent.last_child()->is_anonymous()
&& layout_parent.last_child()->children_are_inline()) {
// Block is out-of-flow & previous sibling was wrapped in an anonymous block.