Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS rgba transparency bug in Chrome?

Just placing a DIV with white background and any opacity value:

background-color: rgba(255, 255, 255, .5);

over a white (255x3) background. Actually DIV's background will be 254/254/254. This happen only in Chrome. FF/IE/Opera/Safari is ok.

Bug?

like image 863
Levon Avatar asked Sep 24 '13 03:09

Levon


People also ask

How do I make a background transparent in rgba CSS?

Transparency using RGBA In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) - which specifies the opacity for a color. An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

How do I turn off transparency in CSS?

If you want to remove the opacity or transparency from the sticky navigation bar, just navigate to Theme Options -> General -> Additional CSS and copy/paste this code and save changes. You could also manipulate the opacity by altering the value “1” at the end of the CSS statement.

How do I make rgba transparent?

So how do you use RGBA? rgba (100%, 0%, 0%, 1); The fourth value denotes alpha and needs to be between 0.0 (absolute transparency) and 1.0 (absolute opacity). For example, 0.5 would be 50% opacity and 50% transparency.

What's the difference between using opacity and rgba transparency in CSS?

The primary difference is, the opacity applies to its sub-elements too. In contrast, rgba() applies the transparency of the colour to that particular element only. For example, opacity is set to the div element that contains text and has a border.


3 Answers

This looks like a bug!

I can confirm this misbehaviour. Got it also by using background: rgba(255,255,255,0.1). More weird: the calculated style says background-color: rgba(255, 255, 255, 0.0980392)

It is hard to see on cheaper displays using TN technology, but still possible to screenshot and measure with e.g. Photoshop.

This question is similar to:
webkit bug: input's background gets gray without any reason on focus?

like image 133
Möhre Avatar answered Oct 17 '22 07:10

Möhre


The weird behaviour is still present in Chrome 38 and Canary 40. The fix that worked for me was to add a transform: translateZ(0); to the div with the rgba background.

like image 43
Stelian Avatar answered Oct 17 '22 09:10

Stelian


This can now be fixed with the new will-change property. Specifically, will-change: transform;

like image 20
James Smith Avatar answered Oct 17 '22 07:10

James Smith