diff --git a/Tests/LibWeb/Ref/reference/scrollable-contains-box-with-gradient-background-ref.html b/Tests/LibWeb/Ref/reference/scrollable-contains-box-with-gradient-background-ref.html
new file mode 100644
index 00000000000..e586cd0d4b7
--- /dev/null
+++ b/Tests/LibWeb/Ref/reference/scrollable-contains-box-with-gradient-background-ref.html
@@ -0,0 +1,23 @@
+
+
+
diff --git a/Tests/LibWeb/Ref/scrollable-contains-box-with-gradient-background.html b/Tests/LibWeb/Ref/scrollable-contains-box-with-gradient-background.html
new file mode 100644
index 00000000000..904b2c2dd67
--- /dev/null
+++ b/Tests/LibWeb/Ref/scrollable-contains-box-with-gradient-background.html
@@ -0,0 +1,30 @@
+
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
index 9bf3419ec42..1782d852e5d 100644
--- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
@@ -159,6 +159,15 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
clip_shrink.right = context.rounded_device_pixels(border_right.width);
}
+ CSSPixelPoint enclosing_scroll_offset;
+ if (is(layout_node.paintable())) {
+ auto const& paintable_box = static_cast(*layout_node.paintable());
+ enclosing_scroll_offset = paintable_box.enclosing_scroll_frame_offset().value_or({});
+ } else if (is(layout_node.paintable())) {
+ auto const& inline_paintable = static_cast(*layout_node.paintable());
+ enclosing_scroll_offset = inline_paintable.enclosing_scroll_frame_offset().value_or({});
+ }
+
// Note: Background layers are ordered front-to-back, so we paint them in reverse
for (auto& layer : resolved_background.layers.in_reverse()) {
DisplayListRecorderStateSaver state { display_list_recorder };
@@ -167,9 +176,9 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
auto clip_box = get_box(layer.clip, border_box, layout_node);
CSSPixelRect const& css_clip_rect = clip_box.rect;
- auto clip_rect = context.rounded_device_rect(css_clip_rect);
+ auto clip_rect = context.rounded_device_rect(css_clip_rect.translated(enclosing_scroll_offset));
display_list_recorder.add_clip_rect(clip_rect.to_type());
- ScopedCornerRadiusClip corner_clip { context, clip_rect, clip_box.radii };
+ ScopedCornerRadiusClip corner_clip { context, context.rounded_device_rect(css_clip_rect), clip_box.radii };
if (layer.clip == CSS::BackgroundBox::BorderBox) {
// Shrink the effective clip rect if to account for the bits the borders will definitely paint over