dourangdz750379 2013-01-18 12:21
浏览 19
已采纳

CSS还是PHP? 颜色是原始的80%,但没有“透明度”?

this might be a tough question.

I have a php function that returns a color value in rgba() with an argument $alpha.

function colorWheel($alpha) {

   "rgba(170, 135, 178, ".$alpha.")"
   …
}

So when calling …

.title { color: <?php echo colorWheel(.8); ?>; }

… I get rgba(170, 135, 178, .8);


The problem I have with this is that the color is "transparent" and shows "overlays".

enter image description here

However what I really like to have is just 80% of the color value! Without any transparent overlays.

The question is now how to solve this?

Any creative ideas how to do that? I don't need to use rgba() it's just the easiest thing that came to my mind. Is there a CSS way not to blend overlaying shapes that have an alpha value?

Or is there a php solution to calculate a the 80% version of rgb(170, 135, 178)? It is important that this calculation works dynamically with the function because there are more colors in the function - this is a follow-up question to "How to return a color-value based a date and random?"!

Thank you in advance.

  • 写回答

3条回答 默认 最新

  • dpbtbcz6650 2013-01-18 12:25
    关注

    that should do it:

    function colorWheel($alpha) {
        $r = round(170 * $alpha);
        $g = round(135 * $alpha);
        $b = round(178 * $alpha);
        "rgba($r, $g, $b, 1)";
        …
    }
    

    well, that makes the color darker, if you want to make it lighter you have to put alpha to a value > 1, and also check if r,g or b goes over 255 and set it to 255 if it does

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序