简体   繁体   English

重复线性梯度在折痕处突然切割

[英]repeating-linear-gradient suddenly cuts under the fold

On my site , I'm having issues with the repeating-linear-gradient element in CSS. 我的网站上 ,CSS中的repeating-linear-gradient元素存在问题。 For the majority of the page, the background looks ok. 对于页面的大部分,背景看起来都不错。 But suddenly, when I scroll down, it looks as if the gradient just shifts one bar to the right and makes my page look ugly. 但是突然之间,当我向下滚动时,渐变似乎只是向右移动了一个小节,使我的页面看起来难看。 This is what I currently have as CSS: 这是我目前拥有的CSS:

    background:repeating-linear-gradient(45deg,transparent,transparent 50px,rgba(255,255,255,.1) 50px,rgba(255,255,255,.1)100px), #81D4FA;

I'm really having trouble, and it would be great if someone could help me. 我真的遇到了麻烦,如果有人可以帮助我,那将是很棒的。 Thanks. 谢谢。

As was mentioned in the comments, background-attachment: fixed; 如评论中所述, background-attachment: fixed; will prevent the seam from being visible, but the stripes do not scroll with the page. 将防止看到接缝,但条纹不会随页面滚动。

According to MDN : 根据MDN

A repeating CSS linear gradient is not a CSS <color> but an image with no intrinsic dimensions; 重复的CSS线性渐变不是CSS <color>而是没有内在尺寸的图像。 that is, it has no natural or preferred size, nor ratio. 也就是说,它没有自然的或首选的大小,也没有比率。 Its concrete size will match the one of the element it applies to. 其具体大小将与它所应用的元素之一匹配。

This means that the positioning of the edge of the image depends on the size of the element, and a 45deg line will not line up with its neighbors unless one of the dimensions is a multiple of the other. 这意味着图像边缘的位置取决于元素的大小,并且45deg线不会与其相邻元素对齐,除非其中一个尺寸是另一个尺寸的倍数。 I recommend making a tile-able image in your image editor of choice and loading it as an asset rather than using repeating-linear-gradient() if you don't want the background to be fixed in place. 如果您不希望将背景固定在适当的位置,建议您在所选的图像编辑器中制作一个可平铺的图像,并将其作为资产加载,而不要使用repeating-linear-gradient()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM