惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - loverain

透不过气 2017年终总结 linux shell中单引号、双引号、反引号、反斜杠的区别 linux系统/var/log目录下的信息详解 SQL 显示表名显示列名 outlook署名最后一行没换行 SSH(poderosa)を使って、さくらのMySQLサーバーに接続する方法 内网IP外网IP的关联及访问互联网原理 用EXCLE群发outlook邮件 本地开发环境搭建(windows) html绝对路径,相对路径 各种进制问题 在浏览器地址栏按回车、F5、Ctrl+F5刷新网页的区别 利用googleapis在日文系统中改善中文字 在css嵌套中的html的table里的字左右不对齐 在共有文件夹中删除某个人的权限的方法 博文阅读密码验证 - 博客园 関係ない話だけど 博文阅读密码验证 - 博客园
CSS3下的渐变文字效果实现
loverain · 2017-10-03 · via 博客园 - loverain

如下,第一种方法已实践

一、方法一:借助mask-image属性

可以狠狠地点击这里:CSS3下的渐变文字效果方法一demo

如果您手头上的浏览器是Chrome或是Safari,则您可以在demo页面中看到类似下面的效果:
方法一下的文字渐变效果 张鑫旭-鑫空间-鑫生活

相应的HTML代码如下:

<h2 class="text-gradient" data-text="天赐美妞">天赐美妞</h2> 

与HTML相对应的CSS代码如下:

.text-gradient {  
    display: inline-block;
    font-family: '微软雅黑';
    font-size: 10em;
    position: relative; 
}  
  
.text-gradient[data-text]::after {  
    content: attr(data-text);  
    color: green;  
    position: absolute;  
    left: 0;  
    z-index: 2;
    -webkit-mask-image: -webkit-gradient(linear, 0 0, 0 bottom, from(#ff0000), to(rgba(0, 0, 255, 0)));
}

从CSS代码可以看出,效果的实现除了“content内容生成技术”以外,主要是使用了mask-image属性,内容则是“webkit核心浏览器下的渐变”了。

二、方法二:background-clip + text-fill-color下的实现

您可以狠狠地点击这里:CSS3下的渐变文字效果方法二demo

如果您手头上的浏览器是Chrome或是Safari,则您可以在demo页面中看到类似下面的效果:
方法二下的文字渐变效果 张鑫旭-鑫空间-鑫生活

此处实现相对上面要简单些,HTML代码如下:

<h2 class="text-gradient">天赐美妞</h2>

与HTML相对应的CSS代码如下:

.text-gradient {  
    display: inline-block;
    color: green;
    font-size: 10em;
    font-family: '微软雅黑';
    background-image: -webkit-gradient(linear, 0 0, 0 bottom, from(rgba(0, 128, 0, 1)), to(rgba(51, 51, 51, 1)));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}; 

CSS代码中关键有用的其实就是最后三行:

background-image: -webkit-gradient(linear, 0 0, 0 bottom, from(rgba(0, 128, 0, 1)), to(rgba(51, 51, 51, 1)));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;

此方法虽然使用的CSS属性相对多些,但是结构简单,易于控制,颜色的选取与控制也更精确,理解上也更容易理解。我个人是推荐使用方法二的。

三、结语

由于目前text-fill-colormask-image属性貌似就webkit核心的浏览器支持,所以两个demo页面只能在Chrome浏览器或是Safari浏览器下才能看到渐变效果。Firefox浏览器下纯色,IE下就更不用说了。

但是,文字渐变本身就是装饰性的功能,所以,本着渐进增强的原则,我们在实际项目中其实是可以大胆使用的。在不影响原来功能基础上,几行CSS代码,让占有率愈来愈高的Chrome浏览器下有更好的视觉体验效果,何乐而不为呢?

就这些。感谢阅读。参考文章:Quick Tip: Nonintrusive CSS Text Gradients

转载自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com]
本文地址:http://www.zhangxinxu.com/wordpress/?p=1601

十大字体

http://www.html5tricks.com/10-cool-html5-text-animation.html