In PHP file I have variable $number
that contains information about font size and it works great:
echo "<div style='font-size:".$number."'px> .... "
And now I wonder, if this possible to change background of this div
depending on the size of the font? Default value is white, so it could be <div style='background-color:#FFFFFF;font-size:10px
for font size 10px. I would like color changes slightly when background font-size is bigger, for example from white through color red, to dark red. How can I do that?
I know it can be done in this way, but I believe it should be easier way than that:
if ($number==10) $color="FFFFFF";
elseif ($number==11) $color="FCEFF3";
....
elseif ($number==50) $color="FF004E";
echo "<div style='background-color:#".$color.";font-size:".$number."'px> .... "
But in above example problem is about long size of script, because font size can be from 10 to 50 or even 80, so I thought maybe I can add hex color values to increase them, somehow?
You can just create an associative array of the colors that you want and make the key the font size. Then, you can simply reference the color from whatever $number
is set to:
$number = 11; // Or whatever the font-size is set to
$backgrounds = array(
10 => "#FFFFFF",
11 => "#FCEFF3",
50 => "#FF004E"
);
echo "<div style='background-color: ".$backgrounds[$number]."; font-size: {$number}px;'></div>";