0

A CSS linear gradient background element has fuzzy transitions between colours even when the stops are at the same spot.

I have an element with the background defined like so:

background:linear-gradient(to right,
    blue, blue 10%,
    red 10%, red 30%,
    yellow 30%, yellow 40%,
    green 40%, green 50%,
    black 50%
  );

In Firefox, the transitions between the colours are fuzzy. If I use a repeating-linear-gradient the edges are crisp. Both are crisp in Chrome.

I have an example pen here: https://codepen.io/anon/pen/rPVWZE?editors=1100#0

Any ideas on how to fix this?

Quasipickle
  • 4,383
  • 1
  • 31
  • 53

1 Answers1

2

Here the effect on FF. I drew some pixels to show zoom level:

enter image description here

A workaround:

.linear{
  height:100px;
  
  background-image:
        linear-gradient(to right, blue 0, blue 100px),
        linear-gradient(to right, red 0, red 100px),
        linear-gradient(to right, yellow 0, yellow 100px);
  
  background-size:
        100px 100px,
        100px 100px,
        100px 100px;
  
  background-position:
        0 0,
        100px 0,
        200px 0;
  
  background-repeat: no-repeat;
}
<div class = "linear"></div>
SirPilan
  • 4,649
  • 2
  • 13
  • 26
  • Your answer seems really complicated - but it does seem to be the only actual working solution. I was hoping there was a flag or obscure css property that would allow the gradient to actually do what I told it to. Thanks for the answer. – Quasipickle Jan 23 '19 at 21:49