How can I prevent CSS gradient banding?

后端 未结 7 1743
别那么骄傲
别那么骄傲 2020-12-05 06:20

I started using CSS gradients, rather than actual images, for two reasons: first, the CSS gradient definitely loads faster than an image, and second, they aren\'t supposed t

相关标签:
7条回答
  • 2020-12-05 07:15

    I know you won't like the sound of this, but the only real way right now to get a consistent cross-browser aesthetic in this case, is to use a repeating image.

    If it's a simple linear gradient, then you only need it to be 1px wide and as high as the gradient, then make the background colour of the page as the final colour of the gradient so it runs smoothly. This will keep file size tiny.

    If you want to reduce gradient bands in your image, use a PNG (not transparency) as I find these to be better suited than JPG's for this purpose.

    In Adobe Fireworks, I would export this as a PNG-24.

    Good luck.

    http://codepen.io/anon/pen/JdEjWm

    #gradient {
      position: absolute;
      width: 100%;
      height: 100%;
      background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(black), to(white));
      background: -webkit-linear-gradient(top, black, white);
      background: -moz-linear-gradient(top, black, white);
      background: -ms-linear-gradient(top, black, white);
      background: -o-linear-gradient(top, black, white);
      background: linear-gradient(top, black, white);
    }
    
    0 讨论(0)
提交回复
热议问题