CSS文本渐变颜色基础教程的三种实现
2020/04/03 19:36 • 网页后端
UI设计师在Web后端开发过程中,经常会设计一些带有渐变文字的设计图。 以前css文字颜色渐变,我们只能使用 png 图片来替换文本。 明天我们就可以用纯CSS来实现渐变文字了。 下面将介绍3种实现方法供大家参考! 基本样式: .gradient-text{text-align:left;text-indent:30px;line-height:50px;font-size:40px;font
css文本颜色渐变的三种实现
UI设计师在Web后端开发过程中,经常会设计一些带有渐变文字的设计图。 以前,我们只能使用 png 图片来替换文本。 明天我们就可以用纯CSS来实现渐变文字了。 下面将介绍3种实现方法供大家参考!
基本风格:
.gradient-text{text-align: left;text-indent:30px;line-height: 50px;font-size:40px;font-weight:bolder; position: relative; }
第一种方式,使用background-cli、text-fill-color:
.gradient-text-one{
background-image:-webkit-linear-gradient(bottom,red,#fd8403,yellow);
-webkit-background-clip:text;
-webkit-text-fill-color:transparent;
}
阐明:
第二种方式,使用 mask-image:
.gradient-text-two{
color:red;
}
.gradient-text-two[data-content]::after{
content:attr(data-content);
display: block;
position:absolute;
color:yellow;
left:0;
top:0;
z-index:2;
-webkit-mask-image:-webkit-gradient(linear, 0 0, 0 bottom, from(yellow), to(rgba(0, 0, 255, 0)));
}
阐明:
mask-image 与background-image 相同css文字颜色渐变,只不过该值可以是图像路径或渐变颜色。
第三种方式,使用线性渐变,填充:
.gradient-text-three{
fill:url(#SVGID_1_);
font-size:40px;
font-weight:bolder;
}
阐明:
在 SVG 中,渐变主要有两种类型:
除了图形元素之外,SVG 中的渐变还可用于填充文本元素
dom 示例:
CSS3渐变字体
*{margin:0;padding:0;}
body,html{width:100%;height:100%;}
.wrapper{width:80%;margin:0 auto;margin-top:30px;}
.gradient-text{text-align: left;text-indent:30px;line-height: 50px;font-size:40px;font-weight:bolder; position: relative; }
.gradient-text-one{
background-image:-webkit-linear-gradient(bottom,red,#fd8403,yellow);
-webkit-background-clip:text;
-webkit-text-fill-color:transparent;
}
.gradient-text-two{
color:red;
}
.gradient-text-two[data-content]::after{
content:attr(data-content);
display: block;
position:absolute;
color:yellow;
left:0;
top:0;
z-index:2;
-webkit-mask-image:-webkit-gradient(linear, 0 0, 0 bottom, from(yellow), to(rgba(0, 0, 255, 0)));
}
.gradient-text-three{
fill:url(#SVGID_1_);
font-size:40px;
font-weight:bolder;
}
方法1. background-clip + text-fill-color
花样年华
方法2. mask-image
豆蔻年华
方法3. svg linearGradient
疗效如下:
发表评论