”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > Why Are There Stripes in My Linear Gradient Background, and How Can I Fix Them?

Why Are There Stripes in My Linear Gradient Background, and How Can I Fix Them?

发布于2025-04-16
浏览:810

Why Are There Stripes in My Linear Gradient Background, and How Can I Fix Them?

Banishing the Background Stripes from Linear Gradient

When employing the linear-gradient property for a background, you may encounter noticeable stripes when the direction is set to top or bottom. These unsightly artifacts can be attributed to a complex background propagation phenomenon.

In case of a vertically-oriented gradient, the margin of the body element propagates to the HTML element, resulting in an 8px tall area. Subsequently, the linear-gradient extends across this entire height, producing repeating patterns.

Solution:

To address this issue, ensure that the body element has a sufficient height. By specifying a height of any value greater than 0 (e.g., 100vh), you can prevent the background from collapsing and eliminate the distracting stripes. This resolves the propagation issues, allowing the linear gradient to be applied smoothly without disruptions.

<div><div class="snippet-code">
<pre> height: 100vh;
background: linear-gradient(to top, red, yellow);
}</pre>

</p>

最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3