CSS color names + alpha transparency

后端 未结 2 1286
隐瞒了意图╮
隐瞒了意图╮ 2021-02-18 16:59

Is it possible to define a color in CSS by its name plus an alpha transparency value?

I.e.:

#mytext { color: red 0.5 }

rather than reso

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-18 17:15

    You can achieve the result you want this way:

    #mytext{
      color: red;
      opacity: 0.5;
    }
    

    Note that opacity will affect the whole element, not just the text, so for example, if the #mytext element had a background color, that would also receive the opacity value of 0.5

    However, I agree with Dai, using color names instead of hex or rgb codes isn't something you should rely on too much. It's an ugly color palette to work with.

提交回复
热议问题