1

I am trying to assign a style to an element where its attribute index=0 The selector :first-letter is not working.

How can do it the selector by attribute (in this case [index='0'] )?

My desired output for the first element is: Text 0 Paragraph (red text)

p[index='0']{
  color:red;
}

p[index='0']{
  text-transform: lowercase;
}

p[index='0']:first-letter {
  text-transform: uppercase;
}
<p index="0">TEXT 0 PARAGRAPH</p>
<p index="1">TEXT 1 PARAGRAPH</p>
<p index="2">TEXT 2 PARAGRAPH</p>
<p index="3">TEXT 3 PARAGRAPH</p>
yavgz
  • 275
  • 3
  • 17
  • Does this answer your question? [Lower case all then capitalize - pure CSS](https://stackoverflow.com/questions/21827377/lower-case-all-then-capitalize-pure-css) – Joseph Webber Jun 15 '23 at 04:00

1 Answers1

1

:first-letter only work on the first word. If your text is short you can use :first-line. Otherwise you need to use js to transform it

p[index='0']{
  color:red;
  text-transform: lowercase;
}

p[index='0']:first-line{
  text-transform: capitalize;
}
Tony
  • 1,106
  • 1
  • 10
  • 17