You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome浏览器box shadow滚动后出现灰色线条bug技术问询

Fixing Chrome's Box Shadow Glitch on Scroll

Hey, I’ve dealt with this exact frustrating box shadow glitch in Chrome before—nothing makes you question your CSS like a random gray line popping up only after scrolling! Here are the most reliable fixes that worked for me and other devs in similar situations:

  • Force GPU acceleration for the navbar
    Chrome’s rendering engine sometimes messes up element layers during scroll, causing shadow artifacts. Adding a simple transform to your navbar forces it into a separate GPU layer, which usually fixes the issue:

    .your-navbar-class {
      transform: translateZ(0);
      /* Or use will-change: transform; if you prefer a more explicit hint */
      /* will-change: transform; */
    }
    

    Note: will-change is great for performance hints, but translateZ(0) has broader compatibility for older Chrome versions.

  • Replace box-shadow with a pseudo-element shadow
    Sometimes the native box-shadow property has rendering quirks in Chrome during scroll. Try simulating the shadow using a pseudo-element instead:

    .your-navbar-class {
      position: relative;
      /* Remove the original box-shadow here */
    }
    
    .your-navbar-class::after {
      content: "";
      position: absolute;
      bottom: -4px; /* Adjust based on your shadow's offset */
      left: 0;
      right: 0;
      height: 4px; /* Match your shadow's blur/diffusion size */
      background: linear-gradient(to bottom, rgba(0,0,0,0.1), transparent); /* Adjust color to match your shadow */
      filter: blur(2px);
      z-index: -1;
    }
    

    This bypasses the native shadow rendering and gives you more control over how the shadow is drawn during scroll.

  • Check for overflow conflicts
    If your navbar or its parent element has overflow: hidden set, this can sometimes clip the shadow incorrectly during scroll operations. Try removing or adjusting the overflow property to see if that resolves the gray line:

    .your-navbar-class {
      /* Remove overflow: hidden; if present */
      overflow: visible;
    }
    

    Double-check parent containers too—sometimes the issue comes from a higher-level element clipping the shadow unexpectedly.

  • Update Chrome to the latest version
    This might seem obvious, but many rendering glitches are known bugs that get fixed in newer Chrome releases. Head to chrome://settings/help to check for updates and install any available patches.

Quick Debug Tip

Open Chrome DevTools (F12) and go to the Layers panel (under More Tools > Layers). Watch how your navbar’s layer behaves during scroll—if you see the layer shifting or flickering, that confirms it’s a rendering layer issue, and the GPU acceleration fix should be your first stop.

内容的提问来源于stack exchange,提问作者Alburkerk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:05:39