【问题标题】:CSS: Repeat a linear gradient inverselyCSS:反向重复线性渐变
【发布时间】:2016-08-10 07:17:11
【问题描述】:

有没有办法让渐变背景的每个交替重复都反转?目前我有以下 CSS:

html {
  background: white; /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(blue, white); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(blue, white); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(blue, white); /* For Firefox 3.6 to 15 */
  background: linear-gradient(blue, white); /* Standard syntax */

  background-size: cover;
  height: 100%;
}

body {
  height: 100%;
}
<html>
  <head>
  </head>
  <body
    Hello world
  </body>
</html>

目前它从上到下从蓝色变为白色,但当我向下滚动时,它再次从蓝色重复到白色例如。 blue-&gt;white; blue-&gt;white; blue-&gt;... 。我希望它来自blue -&gt; white -&gt; blue -&gt; white -&gt;...

【问题讨论】:

  • 为什么不做类似背景的事情:线性渐变(蓝色,白色,蓝色);并从中调整?
  • 这里有类似的东西。我知道您有这样的背景,并且在某些行动中,您想要相反的效果,不是吗? stackoverflow.com/questions/19318534/…

标签: html css repeat linear-gradients


【解决方案1】:

您可以使用repeating-linear-gradient实现如下:

html {
  background: white;
  background: repeating-linear-gradient(blue, white 100vh, white 100vh, blue 200vh);
  height: 1980px;
}

body {
  height: 100%;
  margin: 0;
}

【讨论】:

    【解决方案2】:

    移除高度:100%;从身体检查它

    或查看此网站以使您的页面更漂亮http://colorzilla.com/gradient-editor

    【讨论】:

      【解决方案3】:

      我知道你有这样的背景,在某些行动中,你想要相反的效果。为此,您可以使用transform: scaleY(-1)。您可以在:before{} 中的伪元素中使用渐变,以防止子元素继承父样式。

      div{
        height: 100px;
        width:100%;
        float:left;
        margin-top:20px;
      }
      .div1 {
        background: white; /* For browsers that do not support gradients */
        background: -webkit-linear-gradient(blue, white); /* For Safari 5.1 to 6.0 */
        background: -o-linear-gradient(blue, white); /* For Opera 11.1 to 12.0 */
        background: -moz-linear-gradient(blue, white); /* For Firefox 3.6 to 15 */
        background: linear-gradient(blue, white); /* Standard syntax */
        background-size: cover;
      }
      
      .div2 {
        -webkit-transform: scaleY(-1);
        transform: scaleY(-1);
      }
       <body>
      <div class="div1"></div>
      <div class="div1 div2"></div>
      </body>

      【讨论】:

        猜你喜欢
        • 2011-05-12
        • 2021-06-10
        • 1970-01-01
        • 2020-08-28
        • 2011-11-13
        • 1970-01-01
        • 1970-01-01
        • 2014-06-09
        相关资源
        最近更新 更多