Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser handling of CSS “transparent” in gradients

Although the CSS colors rgba(255,255,255,0) and rgba(0,0,0,0) are apparently the same, i.e. transparent, when being looked at as plain colors, they affect the intermediate colors in gradients:

linear-gradient(left center, rgba(0,0,0,0), rgba(255,255,255,1))

This yields grey semitransparent tones between the two ends.

Now my questions:

  1. Do browsers select the “right” color for transparent automatically or is it a fixed color (most likely “black transparent” or “white transparent”)?

  2. Is this different between browsers?

like image 950
flying sheep Avatar asked Aug 30 '11 10:08

flying sheep


People also ask

How do you add transparency to a gradient in CSS?

To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).

What browsers support linear gradient?

Cross Browser Compatibility Solution For CSS Linear Gradient. All desktop browsers including Internet Explorer 11 and Microsoft Edge provide browser support for Linear CSS Gradients, meaning these CSS Gradients offer excellent cross browser compatibility.

Can you do gradients in CSS?

CSS defines three types of gradients: Linear Gradients (goes down/up/left/right/diagonally) Radial Gradients (defined by their center) Conic Gradients (rotated around a center point)

What are the three main types of gradients in CSS?

There are 3 different CSS gradients: linear, conic, and radial. Each gradient uses a CSS function to pass in multiple color arguments. The colors can be in the format of hex, hsla, rgba or named colors. In addition, you can pass in direction and angles to specify the shape and transition of the gradient.


1 Answers

  1. Although the Color module states that transparent means the same as rgba(0, 0, 0, 0), colors behave a little differently in CSS gradients. The Image Values module states that color stops should be interpolated in a premultiplied RGBA color space. This means that browsers are supposed to preserve the RGB colors during transitions between color-stops, and that the grey semitransparent tones shouldn't be there.

  2. As of the end of October 2012, only IE10 and Opera perform this interpolation correctly, such that the grey portions aren't present and that you get a pure white 0%-to-100% alpha gradient. Other browsers display the grey portions, which is incorrect.

like image 165
BoltClock Avatar answered Oct 05 '22 19:10

BoltClock