0

I am trying to change each letter styles but I'm restricted from using javascript and without using span for each letters , I searched got some pseudo nth-letter but this not working , I know this type of question asked before but the restrictions force me to add this question.

please give some suggestions , it is really helpful

.change:nth-letter(3)
{
color:red;
font-size:20px;
}
<p class="change"> Color </p>
fedesc
  • 2,554
  • 2
  • 23
  • 39

2 Answers2

2

This is a hack that uses:

  • a monospace font so that each letter has a uniform width
  • inline display so that the width of the container is as much as its text
  • uses experimental background-clip: text to clip the background on to the text
  • uses a linear-gradient to color each letter

See demo below:

.change {
  font-size: 20px;
  font-family: monospace;
  display: inline;
  -webkit-background-clip: text;
  background-clip: text;
  color:transparent;
  background-image: linear-gradient(to right, black 40%, red 40% 60%, black 60%);
}
<p class="change"> Color </p>
kukkuz
  • 41,512
  • 6
  • 59
  • 95
-2

I think, you cannot use pseudo elements as :second-letter or :third-letter. The possible way to select first and last word follow below.

.hello:first-letter {
  color:red;
}
.hello:after {
  color: red;
  content: "r";
}
<p class="hello">Colo</p>
Saravana
  • 3,389
  • 4
  • 21
  • 37