Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari doesn't render css gradient text

Tags:

html

css

safari

I'm trying to make gradient text in webkit browsers using this CSS code:

.text {
    background: -webkit-linear-gradient(blue, green);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

it works perfectly in Chrome, but in Safari (both 8 and 9) it doesn't render gradient text unless you select it via mouse click+drag over it.

HTML is as follows:

<p class = "text">Hello world.</p>

Spent 2 evening on that. Found a lot of recommendations to use this method with couple issues similar to mine and no solutions at all. Would appreciate a lot if someone would help.

IMPORTANT UPDATE:

I've found out, that this code works great when applied to single <p> element, but fails to render in Safari (not in chrome) when applied to div wrapper to single or multiple <p> elements like this:

<div class = "text">    
   <p>First line.</p>
   <p>Second, way longeeeeeeer line. </p>
   <p>Third line, just to see gradient span over multiple lines. </p>
</div>

Any thoughts why this could be the case or how to overcome this?

like image 937
o3inc Avatar asked Aug 19 '15 00:08

o3inc


2 Answers

I know it's an old question but in case someone still needs it: I had the same problem and what worked for me was to add a text-shadow to it and make the shadow transparent.

.text {
background: -webkit-linear-gradient(blue, green);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0px 0px #00000000; <--
}

Note that I added '00' to the end of the HEXA code which leads to transparency if someone doesn't know!

like image 86
Swifter Avatar answered Sep 19 '22 18:09

Swifter


I found a simple fix for this

.text, span {
 display: block;
}
like image 44
joonas Avatar answered Sep 18 '22 18:09

joonas