-1

My database give mixed font styles, for Example:

" Hi THis is TEST teXT "

I want to capitalization this type of fonts. I found a way, first using lowercase and then ::first-letter to be capitalized. This give the first letter only capital.

But I want capitalization in every first word, is there any way?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Sahin
  • 87
  • 1
  • 3
  • 13

5 Answers5

0

div.c {
  text-transform: capitalize;
}
<html>
<body>
<h2>text-transform: capitalize:</h2>
<div class="c">Hi THis is TEST teXT</div>

</body>
</html>

Try this.

Sumesh TG
  • 2,557
  • 2
  • 15
  • 29
0

In Javascript:

function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
   // You do not need to check if i is larger than splitStr length, as your for does 
       that for you
   // Assign it back to the array
    splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);     
}
// Directly return the joined string
return splitStr.join(' '); 
}

document.write(titleCase("I'm a little tea pot"));

Please see Capitalize First Letter Of Each Word In A String - JavaScript

PHCris
  • 38
  • 9
0

You can use the following if you strictly want to do it in style.css file:

selector{
text-transform: capitalize;
}

Another option is :

{{ textToBeConverted | uppercase }}

Thanks !

Mukul_Vashistha
  • 106
  • 1
  • 5
0

Angular has a inbuilt pipe for this

{{name | titlecase}}

link

https://angular.io/api/common/TitleCasePipe

Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
0

What you want is impossible using pure CSS. Please refer to this answer.

Alternative, you can use it with angular lowercase pipe and titlecase pipe:

{{ textToTransform | lowercase | titlecase }}
Ethan Vu
  • 2,911
  • 9
  • 25
  • with your reference link, they posted "cant do this with pure CSS". but using angular pipe will do right. i want to try using pure css, thats why i created a new ticked. – Sahin Feb 18 '20 at 06:31