htmlcsslinear-gradients

Gradient color in CSS with percentage


I have only basic knowledge on the CSS. I'm trying to give gradient color for one of my ITEM as per below guidelines and the gradient should be vertical.

enter image description here

I tried the below , but only the first color is coming all over the region. I dont understand that 30% and 50%. How to achieve this?

 .myheader {  
  background: linear-gradient(to bottom, #mycolor1 85%, #mycolor2 45%, #mycolor3 10%);       
  }

Solution

  • Eveyrone is giving the to bottom solution but the trivial solution is to consider to top and keep the percentage values you are using in the picture:

    linear-gradient(to top, #mycolor3 10%, #mycolor2 45%, #mycolor1 85%);
    

    example:

    body {
      background: linear-gradient(to top, red 10%, purple 45%, blue 85%);
      margin: 0;
      height: 100vh;
    }

    Concerning the percentage between (50% and 30%), they are probably the color hints (also called color interpolation hints). From the new specification

    Between two color stops there can be a color interpolation hint, which specifies how the colors of the two color stops on either side should be interpolated in the space between them (by default, they interpolate linearly). There can only be at most one color interpolation hint between any two given color stops; using more than that makes the function invalid.

    example:

    body {
      background: 
       /* First gradient with hints*/
       linear-gradient(to top, red 10%, purple 45%, blue 85%) left /45% 100%,
       /* Second gradient with hints*/
       linear-gradient(to top, red 10%,27.5% ,purple 45%, 57% ,blue 85%) right/45% 100%;
      
      
      background-repeat:no-repeat;
      margin: 0;
      height: 100vh;
    }