CSS overlapping elements & opacity issue

Try and think of it like percentage sales. It’s a bit different, but the analogy gives sense of what’s happening. When a $10 item is 80% off, then you take off an additional 20%, it’s’ not 100% off (80% + 20%). You calculate final price like this:

$10 * (1 - 0.8)  = $2 * (1 - 0.2) = $1.60.

50% opacity means, 50% of the light is blocked. So when you stack two 50% opacity elements, that means 50% of the light is blocked and 50% more light is blocked by the additional layer. Since only 50% light is coming through the first layer, only 50% of that additional light is blocked. So the calculation would be:

50% + (50% * 50%) = 75% opacity.

DEMO

.num2 {
    opacity: 0.75;
}

Leave a Comment