Question

I want to be able to color some letters (bases) in a sequence. I can make a function to say 'color this' but I can not say what the color is.

I have made some hsl divs using an internal stylesheet but this doesn't seem to work.

case 1: /*500-550(Raw Score)*/
    $truecol=<div style="text-color: hsl($col,25%, 100%);">/*input*/</div>
    break;

case 2: //550-600
    $truecol=<div style="text-color: hsl($col,35%, 100%);">/*input*/</div>
    break;
case 3: //600-650
    $truecol=<div style="text-color: hsl($col,45%, 50%);">/*input*/</div>
    break;
case 4: //650-700
    $truecol=<div style="text-color: hsl($col,50%, 100%);">/*input*/</div>
    break;
case 5: //700-750
    $truecol=<div style="text-color: hsl($col,55%, 100%);">/*input*/</div>
    break;
case 6: //750-800
    $truecol=<div style="text-color: hsl($col,60%, 100%);">/*input*/</div>
    break;
case 6: //800-850
    $truecol=<div style="text-color: hsl($col,70%, 100%);">/*input*/</div>
    break;
case 7: //850-900
    $truecol=<div style="text-color: hsl($col,80%, 100%);">/*input*/</div>
    break;
case 8: //900-950
    $truecol=<div style="text-color: hsl($col,90%, 100%);">/*input*/</div>
    break;
case 9: //950-1000
    $truecol=<div style="text-color: hsl($col,100%, 100%);">/*input*/</div>
    break;

Do I have to convert rgb to hsl saturation, then back to hexadecimal? It is important that the colors go in a gradient. This is why I use HSL initially.

Was it helpful?

Solution

Firstly, just look at the colour-coding of your PHP in the question. Clearly you can see it's not right.

Put those HTML tags in a string. Preferably with double-quotes, as long as you escape the style attribute correctly. Example:

$truecol = "<div style=\"color: hsl($col,100%,50%);\">...</div>";

Also notice I corrected the other two errors: The style property is color, not text-color, and in hsl the lightness should be 50% for a "normal" colour. At 100% you just get white.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top