且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用CSS在文本中使用线性渐变边框的渐变颜色不起作用

更新时间:2023-01-27 12:57:11

我认为具有此效果的唯一方法是复制文本.一种将获得笔触颜色,另一种将获得背景颜色:

I think the only way to have this effect is to duplicate the text. One will get the stroke coloration and the other the background coloration:

我使用了不同的颜色来更好地识别它们:

I used different colors to better identify them:

span[data-text] {
  display:inline-block;
  font-size:90px;
  font-weight:bold;
  font-family:arial;
  position:relative;
  margin:10px;
}
span[data-text]:before {
  content:attr(data-text);
  text-shadow: 0 2px 20px purple;
  background: linear-gradient(to bottom,red 0%, blue 100%);
  -webkit-text-stroke: 5px transparent;    
  -webkit-background-clip: text;
  background-clip: text;
  color:transparent;
}
span[data-text]:after {
  content:attr(data-text);
  left:0;
  top:0;
  position:absolute;
  background-image: linear-gradient(275deg, green 0%, yellow 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

<span data-text="£1"></span>