HTML Color Codes: Red to Yellow to Green

前端 未结 13 1225
栀梦
栀梦 2020-12-23 11:16

I would like to come up with as many HEX HTML values to have a smooth color gradient from red to green:

I would like this to be similar to the following: http://ww

13条回答
  •  暖寄归人
    2020-12-23 12:13

    I used this in a php page:

    $percent = .....; //whatever the percentage you want to colour
    
    If ($percent <= 50) {
        $red = 255;
        $green = $percent * 5.1;
    }
    
    If ($percent >= 50) {
        $green = 255;
        $red = 255 - ($percent - 50) * 5.1;
    }
    
    $blue = 0;
    

    Your RGB is then ($red, $green, $blue)

    Note: The 5.1 factor dervies from 255/50

提交回复
热议问题