diff --git a/Tests/LibWeb/Ref/item-with-negative-z-index-ref.html b/Tests/LibWeb/Ref/item-with-negative-z-index-ref.html
new file mode 100644
index 0000000000..582ecd227f
--- /dev/null
+++ b/Tests/LibWeb/Ref/item-with-negative-z-index-ref.html
@@ -0,0 +1,8 @@
+
foo
diff --git a/Tests/LibWeb/Ref/item-with-negative-z-index.html b/Tests/LibWeb/Ref/item-with-negative-z-index.html
new file mode 100644
index 0000000000..65c92b3829
--- /dev/null
+++ b/Tests/LibWeb/Ref/item-with-negative-z-index.html
@@ -0,0 +1,13 @@
+foo
bar
diff --git a/Tests/LibWeb/Ref/manifest.json b/Tests/LibWeb/Ref/manifest.json
index e76350ab57..77a1241db5 100644
--- a/Tests/LibWeb/Ref/manifest.json
+++ b/Tests/LibWeb/Ref/manifest.json
@@ -1,4 +1,5 @@
{
+ "item-with-negative-z-index.html": "item-with-negative-z-index-ref.html",
"img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html",
"grid-items-painting-order.html": "grid-items-painting-order-ref.html",
"square-flex.html": "square-ref.html",
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
index 87d6dc70df..0c52ad88ec 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
@@ -27,6 +27,16 @@ void Paintable::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_containing_block.value());
}
+bool Paintable::is_positioned() const
+{
+ if (layout_node().is_grid_item() && computed_values().z_index().has_value()) {
+ // https://www.w3.org/TR/css-grid-2/#z-order
+ // grid items with z_index should behave as if position were "relative"
+ return true;
+ }
+ return computed_values().position() != CSS::Position::Static;
+}
+
void Paintable::set_dom_node(JS::GCPtr dom_node)
{
m_dom_node = dom_node;
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h
index 9243d5adcc..bbef8388b0 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.h
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.h
@@ -56,7 +56,7 @@ class Paintable
public:
virtual ~Paintable() = default;
- [[nodiscard]] bool is_positioned() const { return layout_node().is_positioned(); }
+ [[nodiscard]] bool is_positioned() const;
[[nodiscard]] bool is_fixed_position() const { return layout_node().is_fixed_position(); }
[[nodiscard]] bool is_absolutely_positioned() const { return layout_node().is_absolutely_positioned(); }
[[nodiscard]] bool is_floating() const { return layout_node().is_floating(); }