Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS linear gradient transparency misbehaving only in Safari

Tags:

Something really strange is happening in Safari. I'm doing a simple gradient overlay to do a text fade effect. It works fine in Firefox and Chrome, but not Safari, which I find strange since Safari and Chrome are both Webkit based.

Safari

enter image description here

Chrome and Firefox

enter image description here

CSS Code

.text-fade {
  background: linear-gradient(to top, white, transparent);
  bottom: 0;
  height: 25%;
  margin: 0;
  position: absolute;
  width: 100%;
}
like image 368
CaptSaltyJack Avatar asked Jun 05 '15 18:06

CaptSaltyJack


People also ask

Does Safari support linear gradient?

Safari supports two types of CSS gradients: linear and radial.

How do you add transparency to a linear gradient?

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).


1 Answers

Instead of:

background: linear-gradient(to top, white, transparent);

Try setting your transparent to an rgba color value. For example:

background: linear-gradient(to top, white, rgba(255,255,255,0));

In other words, the rgb value of both colors should match. For example:

background: linear-gradient(to top, red, rgba(255,0,0,0));

As defined by the w3c spec, transparent is black transparent (rgba(0,0,0,0)). That means that when you are in the middle of the transition, some black should appear.

The color seen in Safari is the correct one, as per the specs.

like image 124
Amy Avatar answered Sep 22 '22 05:09

Amy