Why My ::after Horizontal Line Won’t Scroll: Debugging Layer Bugs in Chrome
This article explores a scrolling issue caused by a CSS ::after‑generated line that creates an unexpected rendering layer, explains how will‑change and transform can influence layer creation, and documents the puzzling paint/composite behavior observed during debugging.
Background
The horizontal line should have scrolled together with the page, but it stayed fixed. I learned about layer management from the Udacity browser rendering optimization course, which mentioned layers without detailed explanation. Today I encountered a bug caused by a layer.
Reproducing the Bug
The horizontal line should have scrolled with the page, but it did not:
Inspecting the Layer
The line is drawn using
::after+
position:absolute+
margin, which forces the browser to create a separate rendering layer.
The course mentioned that
will-changeand
transform: translatecan hint the browser to create a layer (though the browser may ignore them).
Trying to add
will-changeor
transformsolved the visual problem, but the layer was not created—it was merged.
Although the issue was fixed, the layer merged instead of being a separate one.
Further inspection shows the Paint count changes while scrolling, but memory usage stays at 0 B because of
layerForVerticalScrollBar. The page also has no visible scrollbar.
Even with the scrollbar disabled,
paintand
compositestill occur.
Additional Observations
Adding
will-changeor
transformresolves the visual glitch, but other issues appear:
The
.mainlayer height changes with scrolling, and both
paintand
compositeare triggered. This suggests scrolling triggers
paint, not only
compositeas expected.
Comparing with another page shows scrolling still occurs on the root layer without triggering
paint, which is puzzling.
Unresolved Questions
Question 1
In Blink,
transformonly results in
composite. Why does
paintstill happen here?
Question 2
Some
::aftergenerated lines do not merge initially, while later ones do. Clicking the right scrollbar reveals partial layer merging without a full page repaint. The cause remains unclear.
If anyone has encountered similar issues or knows relevant articles, please share in the comments.
In hindsight, using
borderfor the line would require extra
divelements, increasing workload; the current approach with
paddingdemonstrates the benefit of a view‑model‑driven layout.
Tencent IMWeb Frontend Team
IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.