Html CSS3文本渐变不起作用?
我试图在一些文本上应用纯CSS3渐变(没有图像等),但文本保持不变 我目前的代码是:Html CSS3文本渐变不起作用?,html,css,text,gradient,Html,Css,Text,Gradient,我试图在一些文本上应用纯CSS3渐变(没有图像等),但文本保持不变 我目前的代码是: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Text Gradients</title> <style> /* The gradient class */ .gradient {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Text Gradients</title>
<style>
/* The gradient class */
.gradient {
-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(252,255,244,1)), color-stop(100%,rgba(233,233,206,1)));
}
</style>
</head>
<body>
<!--The text with the gradient-->
<h1 class="gradient"> Hello World </h1>
</body>
</html>
文本渐变
/*梯度类*/
.梯度{
-webkit遮罩图像:-webkit渐变(线性、左上、左下、颜色停止(0%,rgba(252255244,1))、颜色停止(100%,rgba(233233206,1));
}
你好,世界
仅适用于webkit用户。要支持所有浏览器,您至少需要:
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#000)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ccc, #000); /* for firefox 3.6+ */
将颜色值更改为所需的值
编辑:正如@Lokase所说:您也可以使用他/她的评论中链接的生成器。我建议这样做,这将适用于所有现代浏览器
background-image: linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
background-image: -o-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
background-image: -moz-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
background-image: -webkit-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
background-image: -ms-linear-gradient(bottom, rgb(93,245,172) 22%, rgb(121,255,207) 61%, rgb(158,255,249) 81%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.22, rgb(93,245,172)),
color-stop(0.61, rgb(121,255,207)),
color-stop(0.81, rgb(158,255,249))
);
还可以尝试使用,它允许您添加一些代码,使其在IE浏览器中工作。如果您使用大量CSS3,我建议您使用。这允许您跳过所有浏览器前缀,库将在运行时添加所有必要的前缀
如果您使用它,您的样式将如下所示:
.gradient {
mask-image: gradient(linear, left top, left bottom, color-stop(0%,rgba(252,255,244,1)), color-stop(100%,rgba(233,233,206,1)));
}
我能够在Chrome中使用以下工具生成渐变文本:
h1 {
font-size: 72px;
background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#333));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
尝试使用这个CSS3渐变生成器:+1我通常会生成我的渐变,但这会使css变得更好和更好的抽象(我认为添加到这个工具比返回所有渐变并为出现的任何全新浏览器重新生成更容易):)