如何为<Typography />
组件设置渐变的font-color
样式?
目前我尝试过的方法:
const CustomColor = withStyles({
root: {
fontColor: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
},
})(Typography);
这样不起作用,所以我尝试按照此教程操作,并进行了以下实现:
const CustomColor = withStyles({
root: {
fontSize: 20,
background: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
webkitBackgroundClip: "text",
WebkitTextFillColor: "transparent",
},
})(Typography);
这种方法并没有达到预期的效果,但是至少展现了某种渐变色。
![enter image description here](https://istack.dev59.com/xtoTZ.webp)
<Typography style={{
fontSize: 20,
background: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
webkitBackgroundClip: "text",
WebkitTextFillColor: "transparent",
}}> Hello world! </Typography>
这种方法有点可行,但是根据元素的宽度不同,渐变会发生变化。这是一个不希望出现的行为。另外我想坚持使用
withStyles
样式解决方案。在线演示: 在这里 有什么提示吗?我错过了什么吗?