如何对文本同时使用文本阴影和线性渐变?

How to use both text-shadow and linear-gradient for text?

我尝试同时使用它们,但都失败了..

h1 {
  font-size: 72px;
  background: linear-gradient(to top, black 50%, orange 50%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
<h1>Heading 1</h1>

只使用没有文字阴影的线性渐变:

只使用没有线性渐变的文本阴影:

同时使用:

基于此previous answer,这里是您需要复制文本的想法:

h1 {
  font-family:sans-serif;
  font-size:60px;
  font-weight: bold;
  position:relative;
  margin:20px;
}
h1::before,
h1::after {
  content:attr(data-text);
}
h1::after {
  color:#fff; /*use white*/
  /*create the stroke around text*/
  text-shadow:
    1px 0  0px #000,
    0 1px 0px #000,
    1px 1px 0px #000,
    -1px 0 0px #000,
    0 -1px 0px #000,
    -1px -1px 0px #000,
    -1px 1px 0px #000,
    1px -1px 0px #000;
  mix-blend-mode: darken; /*everything is more dark than white so we always see the background */
}
h1::before {
  position:absolute;
  top:0;
  left:0;
  background:linear-gradient(to bottom,yellow 50%, red 51%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color:transparent;
}
<h1 data-text="Heading 1"></h1>

你有background: linear-gradient(to top, black 50%, orange 50%);的地方,你应该用bottom,
替换它 在你有 1px 0 black 的地方,你应该摆脱 black.

<style>   
h1 {
  font-size: 72px;
  background: -webkit-linear-gradient(bottom, black 50%, orange 50%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: -1px 0, 0 1px, 1px 0, 0 -1px
}
</style>
<h1>Heading 1</h1>

变化:

background: -webkit-linear-gradient(bottom,black 50%, orange 50%); text-shadow: -1px 0black, 0 1pxblack, 1px 0 black, 0 -1pxblack`;