Multi-Colored text using only CSS

后端 未结 2 527
死守一世寂寞
死守一世寂寞 2021-01-01 04:48

I\'m not sure if my title coherently expressed my issue, but I\'ll explain below.

I would like to assign a different color to each character in a st

2条回答
  •  [愿得一人]
    2021-01-01 05:13

    Dumb CSS only solution - where you need to put each letter into separate so you can use :nth-child(2n+1)

    .username span {
      color: red;
    }
    .username span:nth-child(2n+1) {
      color: blue;
    }
    Username

    OR

    you can use small JavaScript like Ryan Rodemoyer suggested in this answer:

    var message = "The quick brown fox.";
    var colors = new Array("#ff0000","#00ff00","#0000ff"); // red, green, blue
    for (var i = 0; i < message.length; i++)
      document.write("" + message[i] + "");

    OR

    maybe you're looking for something like this

提交回复
热议问题