0

如何为 Tailwind CSS 中的文本/标题添加线性渐变?虽然我能够使用这个将它添加到背景中

<h2 className="text-4xl w-full text-white font-extrabold bg-gradient-to-r from-sky-500/20 to-sky-500/75">
       Welcome To <br /> My Personal PortFolio 
</h2>

但我得到了这个 得到

4

2 回答 2

0

添加

-webkit-background-clip: text; /* apply background clip */
-webkit-text-fill-color: transparent;

使您的文本剪辑渐变

h2 {
  font-size: 48px;
  font-weight: 800;
  margin: 0;
}

h2.gradient-text {
  background: -webkit-linear-gradient(45deg, #09009f, #00ff95 80%);
  -webkit-background-clip: text; /* apply background clip */
  -webkit-text-fill-color: transparent;
}
<h2 class="gradient-text text-4xl w-full text-white font-extrabold bg-gradient-to-r from-sky-500/20 to-sky-500/75">
  Welcome To <br /> My Personal PortFolio
</h2>

于 2022-02-21T12:14:55.927 回答
0

经过一个小时的忙碌,我想出了一个办法。

<h2 className="text-4xl w-full text-transparent bg-clip-text font-extrabold bg-gradient-to-r from-white to-sky-500/10 p-2">
       Welcome To <br /> My Personal PortFolio 
</h2>

在此处输入图像描述

于 2022-02-21T12:16:00.967 回答