简体   繁体   English

打印文本,然后使用HTML和CSS更改颜色

[英]Print text and then change colour using HTML and CSS

I was wondering if it is possible to change the colour of my text inside the <a> ... </a> tags, from black to red after a certain time interval and remain permanently red. 我想知道是否可以在一定时间间隔后将<a> ... </a>标记内的文本颜色从黑色更改为红色,并保持永久红色。

do {
  document.getElementById("code").innerHTML +="<a>Hello World</a><br>";
  await sleep(...)
  document.getElementById("code").innerHTML +="<a>Hello World</a><br>";
  await sleep(...)
  document.getElementById("code").innerHTML +="<a>Hello World</a><br>";
  await sleep(...)
  document.getElementById("code").innerHTML +="<a>Hello World</a><br>";
} while {...}

and after this code runs, it should change the first "Hello World" from black to red, then the second "Hello World" will print and change that text colour from black to red, and so on... 在此代码运行之后,应将第一个“ Hello World”从黑色更改为红色,然后第二个“ Hello World”将打印并将该文本颜色从黑色更改为红色,依此类推...

I have explored different methods on this matter... 我在这个问题上探索了不同的方法。

a {
    animation: change 1s step-end both;
}

@keyframes change {
    from { color: black }
    to   { color: red }
}

but what I found to be the problem with this method is that it constantly changes from black to red and back on all the text containing the tags, and the colour change does not remain permanent. 但是我发现这种方法的问题在于,它不断地从黑色变为红色,然后又在包含标签的所有文本上恢复,并且颜色变化不会永久保持不变。

don't use @keyframes. 不要使用@keyframes。 because keyframes works in a loop. 因为关键帧是循环工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM