1

I'm trying to use a text gradient, and it works on Chrome & Safari but on Android it applies the gradient to the content rather than the text (so instead of seeing text with a gradient, you see a box with a gradient — not ideal, especially since the text is important).

Here's my SASS mixin:

@mixin text-gradient($from : #2bd2f2, $to : #218bb2) {
    text-shadow: none;
    background: -webkit-gradient(linear, left top, left bottom, from($from), to($to));
    -webkit-background-clip: text;
    -moz-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

Any idea as to why this doesn't work?

Thanks!

4

1 回答 1

0

这应该适合你。在您的脚本中实现这一点,并根据需要更改您拥有的所有变量。如果一切都失败了,你可以使用它,因为它在 mixin 之外。

该脚本在 Android Chrome 上进行了测试并且可以运行。

h1 {
        text-shadow: none;
        background: #2bd2f2;  /* Failsafe color */
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2bd2f2), color-stop(99%, #218bb2));
        background: -webkit-linear-gradient(top, #2bd2f2 0%, #218bb2 99%);
        background: linear-gradient(to bottom, #2bd2f2 0%, #218bb2 99%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
}

您可能已经发现这种方法与许多浏览器不太兼容。这就是为什么我可能会推荐 html5 中的 canvas 选项来绘制带有渐变的文本。这些链接可以帮助您一路走来。

https://www.inkling.com/read/html5-canvas-fulton-fulton-1st/chapter-3/text-and-the-canvas-context

https://www.inkling.com/read/html5-canvas-fulton-fulton-1st/chapter-3/text-with-gradients-and-patterns

于 2013-09-03T15:30:20.157 回答