简体   繁体   English

可靠地创建重复线性渐变图案

[英]Reliably creating repeating-linear-gradient pattern

I've created an element that uses repeating-linear-gradient as the background image. 我创建了一个使用repeating-linear-gradient作为背景图像的元素。 At the moment, the size of the element adversely effects the background pattern. 目前,元素的尺寸会对背景图案产生不利影响。 My goal is to be able to consistently produce the same background pattern regardless of the size of the element. 我的目标是不管元素的大小如何,都能始终如一地产生相同的背景图案。

I know the simplest way to get this pattern every time is to create a .png with the pattern that can be repeated, but is there anyway to make this without an image? 我知道每次获取此模式的最简单方法是使用可重复的模式创建一个.png,但是是否有没有图像的方法呢? Legacy browser compatibility is not an issue. 旧版浏览器兼容性不是问题。

I'm just looking for suggestions I might not have thought of to solve this experiment. 我只是在寻找解决该实验可能没有想到的建议。

To demonstrate, I've created this code pen . 为了演示,我创建了此代码笔

HTML HTML

<div class="bar"></div>

CSS CSS

.bar {
  display: block;
  width: 695px;
  height: 44px;
  left: 50%;
  margin: -22px -347px;
  position: absolute;
  top: 10%;
  background-color: #4d4d4d;
  background-image: repeating-linear-gradient(45deg, rgba(0, 191, 255, 0.5), rgba(0, 191, 255, 0.5) 1px, transparent 1px, transparent 15px), 
   repeating-linear-gradient(-45deg, rgba(39, 216, 5, 0.59), rgba(39, 216, 5, 0.59) 1px, transparent 1px, transparent 15px);
}
.bar.big {
  width: 1000px;
  top: 25%;
  margin-left: -500px;
  maring-right: -500px;
}
.bar.small {
  width: 400px;
  top: 40%;
  margin-left: -200px;
  maring-right: -200px;
}

Set the background-size for .bar : 设置.barbackground-size

background-size: 695px 44px;

DEMO 演示

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

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