CSS variables and opacity

后端 未结 1 1034
你的背包
你的背包 2021-01-14 06:18

A quick question to which the answer is probably \"NO\", but I\'m new to CSS variables so I\'m not sure.

If I want to define color and later be able to add alpha cha

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 06:59

    You are almost good, you simply need to pay attention to the syntax:

    :root {
      --c:255,0 ,0;
      --o:0.5;
    }
    html {
      background:rgba(var(--c),var(--o));
    }
    body {
       background:rgb(var(--c));
       height:100px;
    }
    .box {
     --c:12,12,12;
     --o:0.7;
     background:rgba(var(--c),var(--o));
     color:#fff;
    }
    some content

    You can also define each channel alone:

    :root {
      --r:255;
      --g:0;
      --b:0;
      --c:var(--r),var(--g) ,var(--b);
      --o:0.5;
    }
    html {
      background:rgba(var(--c),var(--o));
    }
    body {
       background:rgb(var(--c));
       height:100px;
    }
    .box {
     --c:12,12,12;
     --o:0.7;
     background:rgba(var(--c),var(--o));
     color:#fff;
    }
    some content

    0 讨论(0)
提交回复
热议问题