Android上的CSS3文本渐变不工作



我正在尝试使用文本渐变,它适用于Chrome &但是在Android上,它会将渐变应用于内容而不是文本(所以你看到的不是带有渐变的文本,而是带有渐变的框-不理想,特别是因为文本很重要)。

这是我的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;
}

知道为什么这不起作用吗?

谢谢!

这应该适合您。在您的脚本中实现此功能,并根据需要更改所有变量。如果这些都失败了,你可以在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中的画布选项来绘制渐变文本。这些链接可以帮助你一路走来。

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

最新更新