Hex colors: Numeric representation for “transparent”?

后端 未结 8 1091
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 09:56

I am building a web CMS in which the user can choose colours for certain site elements. I would like to convert all colour values to hex to avoid any further formatting hass

8条回答
  •  误落风尘
    2020-12-05 10:03

    The alpha channel defines the transparency value of a color, so any color is 100% transparent as long as the alpha value is 0. Typically this four-channel color type is known as RGBA.

    You can specify RGBA in CSS like so:

    div {
        background: rgba(200, 54, 54, 0.5); /* 50% transparent */
    }
    

    Note that not all browsers support RGBA, in which case you can specify a fallback:

    div {
        background: rgb(200, 54, 54); /* fallback */
        background: rgba(200, 54, 54, 0.5); /* 50% transparent */
    }
    

    More information regarding browser support and workarounds can be found here.

提交回复
热议问题