<!doctype>
<html>
<head>
<style>
div {
background:rgba(0,255,255,0.3);
}
#div1 {
width:300px;
height:300px;
}
#div2 {
width:200px;
height:200px;
}
</style>
</head>
<body>
<div id="div1"><div id="div2"></div></div><br/>
</body>
what is the actually computed transparency of div2? I am confused. It is a unknown number that is not 0.3+0.3 or 0.3+0.3*0.3
The sum of alpha channels can be calculated as:
alpha_top + alpha_bottom * (1 - alpha_top) =
0.3 + 0.3 * (1 - 0.3) =
0.3 + 0.3 * 0.7 =
0.3 + 0.21 =
0.51
For more explanation, see Alpha Compositing @ wikipedia, which lists the formula as:
or
This is essentially the same formula used by Bogdan Kuštan and it can also be found in this answer by bwoebi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With