How do you calculate overlapping rgba values?

不问归期 提交于 2019-12-06 17:33:28

If you set the borders alpha channel to 0, it'll match the background-color. It's where no modifications are made to the underlying color; it's the transparent mode.

To calculate the sum of the alpha-channels it is basically:

alpha-channel of border * (1 - alpha-channel of background) + alpha-channel of background

So the border has effectively an alpha-channel value of 0.5 * (1 - 0.5) + 0.5 = 0.5 * 0.5 + 0.5 = 0.25 + 0.5 = 0.75.

A transparency (alpha) value of 0 for the border-color will make it match the background-color. See: http://en.wikipedia.org/wiki/RGBA_color_space

.example {
    display: inline-block;
    padding: 50px;
    background: rgba(0, 0, 0, 0.5);
    border: 25px solid rgba(0, 0, 0, 0);
}

Fiddle: http://jsfiddle.net/BBdB3/2/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!