问题
I have to set backgroundColor of div using RGB values . Im able to get this way.
<div style="width: 100px; height: 100px; background-color: rgb(255,0,0)">
</div>
Now, Since I also have CMYK (0,1,0.5,0) values , So Can you assist me how to achieve same with these values.
Im doing this way , but no gain .
<div style="width: 100px; height: 100px; background-color: device-cmyk(0, 1, 0.5, 0)">
</div>
Thanks
回答1:
You can't do it directly in CSS. You'll have to convert your CMYK values to their RGB counterparts somewhere else (probably by a server-side script) and use the converted values in your CSS. Note that converting is not actually much different to what the SVG function does.
回答2:
You can use this PHP function or use similar algorithm to implemented by client script language:
function cmyk_to_rgb2($c, $m, $y, $k)
{
$c = (255 * $c) / 100;
$m = (255 * $m) / 100;
$y = (255 * $y) / 100;
$k = (255 * $k) / 100;
$r = round(((255 - $c) * (255 - $k)) / 255) ;
$g = round((255 - $m) * (255 - $k) / 255) ;
$b = round((255 - $y) * (255 - $k) / 255) ;
$o->r = $r ;
$o->g = $g ;
$o->b = $b ;
return $o ;
}
PHP, JavaScript
来源:https://stackoverflow.com/questions/12322208/cmyk-values-as-background-color