gpt4 book ai didi

javascript - 使用线性渐变更改 h1 标签的文本颜色

转载 作者:行者123 更新时间:2023-12-04 07:30:15 26 4
gpt4 key购买 nike

我正在尝试使用线性渐变更改 h1 标签文本的颜色。

document.querySelectorAll('.hud-intro h1')[0].style.color = 'linear-gradient(to right, #7f00ff, #e100ff);'
document.querySelectorAll('.hud-intro h1')[0].style.background = 'linear-gradient(to right, #7f00ff, #e100ff);'
<div id="hud-intro" class="hud-intro">
<h1>NAME HERE<small>.io</small></h1>
</div>

我试过了:
document.querySelectorAll('.hud-intro h1')[0].style.color = 'linear-gradient(to right, #7f00ff, #e100ff);'
document.querySelectorAll('.hud-intro h1')[0].style.background = 'linear-gradient(to right, #7f00ff, #e100ff);'

最佳答案

线性渐变仅适用于背景,因此颜色规则不起作用。但问题是您的代码中有一个不需要的分号:

document.querySelectorAll('.hud-intro h1')[0].style.background = 'linear-gradient(to right, #7f00ff, #e100ff)'
<div id="hud-intro" class="hud-intro">
<h1>NAME HERE<small>.io</small></h1>
</div>

来自 MDN :

Because <gradient>s belong to the <image> data type, they can only beused where <image>s can be used. For this reason, linear-gradient()won't work on background-color and other properties that use the<color> data type.

关于javascript - 使用线性渐变更改 h1 标签的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67975965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com