Aart den Braber
Aart den Braber

Reputation: 862

Gradient banding with alpha channel

I want to create a gradient from #111 to transparent. However, there aren't many colors in between, so I get gradient banding, whatever I do. I tried using an image and several CSS gradient-methods, nothing works.

I just keep seeing the banding, and that is so big a problem that I can't use gradients now. :/

Just a simple test to show you: http://codepen.io/AartdenBraber/pen/GWdapm?editors=1000

It would be best for me if this could be solved with CSS only. I already tried overlapping several gradients, but that only made it worse.

Upvotes: 0

Views: 1660

Answers (1)

Matt McManis
Matt McManis

Reputation: 4675

Some browsers show banding in css gradients.

You could tile a transparent noise png under the css gradient.

http://noisepng.com can generate the image. I used size 500, intensity 90, opacity 6.
You may have to adjust the values to get the desired look.


https://jsfiddle.net/h4075sm0/

HTML

<div class="gradient">
  <div class="noise"></div>    
</div>

CSS

html, body {
  width: 100%;
  height: 100%;  
}

.noise {
  width: 100%;
  height: 100%; 
  background: url('https://i.imgur.com/UNfGD66.png');
}

.gradient {
  width: 100%;
  height: 100%;
  background: -moz-linear-gradient(top,  rgba(17,17,17,1) 0%, rgba(17,17,17,0) 100%); /* FF3.6-15 */
  background: -webkit-linear-gradient(top,  rgba(17,17,17,1) 0%,rgba(17,17,17,0) 100%); /* Chrome10-25,Safari5.1-6 */
  background: linear-gradient(to bottom,  rgba(17,17,17,1) 0%,rgba(17,17,17,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#111111', endColorstr='#00111111',GradientType=0 ); /* IE6-9 */
}

Upvotes: 1

Related Questions