javascript - 如何使用适合屏幕尺寸的渐变颜色为文本着色并在新行上继续颜色?

标签 javascript html css

编写以下代码后,颜色在行尾停止并在下一行重新开始。我希望它继续并以不同的颜色结束,直到它到达第二行的末尾。然后继续这样做。

这是我在 p 标签上使用的 css 类。

$font: 'Poppins', sans-serif;

.text {
    background: linear-gradient(to right, #000000 0%, #4ad7fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font: {
        size: 3vw;
        family: $font;
    };
}

这是我得到的:

enter image description here

这是我的预期:

enter image description here


我可以不使用任何 javascript 来实现吗? 尽管 javascript 也可以。

最佳答案

只需添加一个 display : inline 和一些红色 :

.text {
  display: inline;
  background: linear-gradient(to right, #000 0%, blue 25%, #000 50%, red 75%, #000 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 3vw;
  font-family: "Poppins", sans-serif;
}
<p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero, quo consectetur similique blanditiis explicabo dolorum quam voluptate, accusamus repellat sed ipsam doloribus facere quas perspiciatis veritatis ad dicta. Tenetur, vero?
</p>

关于javascript - 如何使用适合屏幕尺寸的渐变颜色为文本着色并在新行上继续颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53671268/

相关文章:

html - 无论屏幕大小如何,背景图像都适合整个屏幕

html - 我们的通知栏无法按预期在移动设备上运行

javascript - 查看 Chrome 控制台时 video.min.js 出现 "Refused to create worker from blob"错误

php - 原型(prototype) Javascript 框架 - 获取 PHP 响应

html - 输入的文本框太小

IE 中的 html 表格 thead 和 th 背景

html - UL 中断 dvs 内的 html 滚动(使用显示 : box) 时

javascript - 时刻 js 的无效日期

javascript - 单击按钮不是调用该函数吗?

javascript - 当我点击按钮时,没有任何反应