Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Letters overlapping when setting alpha using color

Below I have 2 div tags with the same text. One sets the font transparency using color , and the other using opacity.

In the 2nd tag, I can see the desired result, but in the first one, I see some letters overlapping with each other and that creates a translucent/opaque effect.

Could anyone explain why this font rendering occurs?

EDIT: The issue occurs in Google Chrome

body{ font-family: Lobster; background: black; }
div{ font-size: 100px; }
div:hover{ color: #fff; opacity: 1; }
.alpha{ color: rgba(255, 255, 255, .3); }
.opac{ color: #fff; opacity: .3; }
<link href="https://fonts.googleapis.com/css?family=Lobster&display=swap" rel="stylesheet">
<div class="alpha">Toshio Bando</div>
<div class="opac">Toshio Bando</div>
like image 660
Anurag Srivastava Avatar asked Jan 26 '26 19:01

Anurag Srivastava


1 Answers

In chrome this behaviour is handled correctly. As per the CSS specification the opacity property should be treated as a post-processing operation. RGBA on the other hand is intended to render all individual components separately off-screen, blending them together, and then rendering to the DOM with element properties such as opacity applied in post.

However, this issue will be experienced on both elements when viewing in Firefox due to poor implementation of the CSS specification:

enter image description here

Correct rendering within Chrome:

enter image description here

Code for reproducing the issue cross-browser:

body{ font-family: Lobster; background: black; }
div{ font-size: 100px; }

.alpha:hover{ color: rgba(255, 255, 255, 1); }
.alpha{ color: rgba(255, 255, 255, .3); }

.opac:hover{ color: #fff; opacity: 1; }
.opac{ color: #fff; opacity: .3; }
<link href="https://fonts.googleapis.com/css?family=Lobster&display=swap" rel="stylesheet">
<div class="alpha">Toshio Bando</div>
<div class="opac">Toshio Bando</div>
like image 163
Matt Davis Avatar answered Jan 29 '26 10:01

Matt Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!