【问题标题】:How to use repeating gradient in place of linear-gradient如何使用重复渐变代替线性渐变
【发布时间】:2022-01-10 06:55:15
【问题描述】:

我这里有这个线性梯度代码。 https://jsfiddle.net/0qfy3ks2/

我如何让它使用重复渐变?

所以图像是一样的,只是使用了重复的渐变。

background-image: repeating-linear-gradient

重复渐变不使用 background-size,因为它会破坏重复模式。

.test {
  width: 100px;
  height: 100px;
  background-image: linear-gradient(
      45deg,
      transparent,
      transparent 7px,
      rgb(113, 121, 126) 7px,
      rgb(113, 121, 126) 7.5px,
      transparent 7.5px,
      transparent 10px
    ),
    linear-gradient(
      -45deg,
      transparent,
      transparent 7px,
      rgb(113, 121, 126) 7px,
      rgb(113, 121, 126) 7.5px,
      transparent 7.5px,
      transparent 10px
    );
  background-size: 10px 10px;
}
<div class="test"></div>

【问题讨论】:

    标签: css gradient linear-gradients repeating-linear-gradient


    【解决方案1】:

    你可以做这样的事情吗?您可以通过更改 px 值来更改大小:

    .test {
      width: 100px;
      height: 100px;
      background-size: 8px 8px;
      background:
        repeating-linear-gradient(45deg,
          transparent,
          transparent 4.5px,
          rgba(0, 0, 0, .75) 5px,
          transparent 5.5px,
          transparent 7px),
        repeating-linear-gradient(-45deg,
          transparent,
          transparent 4.5px,
           rgba(0, 0, 0, .75) 5px,
          transparent 5.5px,
          transparent 7px);
    }
    <div class="test"></div>

    【讨论】:

    • 明白了。刚刚编辑为使用重复线性渐变。
    • 您可以编辑 px 值以获得您想要的大小。并编辑 rgb/rgba 值以获得您想要的颜色。我对其进行了编辑以使其更接近
    • 重复渐变不使用背景大小,因为这会破坏重复模式。
    • 不确定你的意思...我的代码使用的是background-size
    猜你喜欢
    • 2017-09-02
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    相关资源
    最近更新 更多