Search code examples
csslinear-gradients

Hard edged gradient in css?


I was trying to replicate this image in pure css using linear gradient.

enter image description here

I tried to use gradient stops, but all the colors are blending. Is there any way to make a linear gradient hard-edged?

I have tried:

  background-image: -webkit-linear-gradient(left, #252525 0%, #f5f5f5 20%, #00b7b7 40%,#b70000 60%, #fcd50e 80%);

and also without using those percentages too, still the same.


Solution

  • What about multiple gradient like this:

    .line {
      height:5px;
      background-image:
        linear-gradient(red,red),
        linear-gradient(blue,blue),
        linear-gradient(yellow,yellow),
        linear-gradient(purple,purple);
      background-size:
        calc(1 * (100% / 4)) 100%,
        calc(2 * (100% / 4)) 100%,
        calc(3 * (100% / 4)) 100%,
        calc(4 * (100% / 4)) 100%;
      background-repeat:no-repeat;
    }
    <div class="line">
    </div>