-5

Input: I AM A STUDENT
Expected Output: I Am A Student
How can I achieve this using css?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Saad Ghojaria
  • 41
  • 1
  • 8

2 Answers2

4

p {
  text-transform: lowercase;
}
p:first-line {
  display: block;
  text-transform: capitalize;
}
<p>I AM A STUDENT</p>
1

You can use the text-transform-property of CSS if the text is lowercase to begin with:

p {
  text-transform: capitalize;
}

If the text is already capitalized you unfortunately can only transform it into lowercase. Alternatively you could us the ::first letter-selector like @Mr Lister suggested and put every word into a span like so:

p {
  text-transform: lowercase;
}

span {
  display: inline-block;
}

span::first-letter {
  text-transform: capitalize;
}
<p> <span>I</span> <span>AM</span> <span>A</span> <span>STUDENT</span> </p>

Other than that you could, of course, do this with JavaScript as discussed in this thread but that should be a last resort.

leonheess
  • 16,068
  • 14
  • 77
  • 112