Here is my HTML:
<a href="#" class="link">small caps</a> &
<a href="#" class="link">ALL CAPS</a>
Here is my CSS:
.link {text-transform: capitalize;}
The output is:
Small Caps & ALL CAPS
and I want the output to be:
Small Caps & All Caps
Any ideas?
I know this is a late response but if you want to compare the performance of various solutions I have a jsPerf that I created.
Regex solutions are the fastest for sure.
Here is the jsPerf: https://jsperf.com/capitalize-jwaz
There are 2 regex solutions.
The first one uses
/\b[a-z]/g
. Word boundary will capital words such as non-disclosure to Non-Disclosure.If you only want to capitalize letters that are preceded by a space then use the second regex
JavaScript:
CSS:
What Khan "ended up doing" (which is cleaner and worked for me) is down in the comments of the post marked as the answer.
capitalize transforms every first letter of a word to uppercase, but it does not transform the other letters to lowercase. So, Use text-transform: uppercase on the first letter, and text-transform: lowercase on the rest. Worked for me.
if you are using jQuery; this is one a way to do it:
Here is an easier to read version doing the same thing:
Demo
all wrong it does exist --> font-variant: small-caps;
text-transform:capitalize; just the first letter cap
May be useful for java and jstl.
In JSP
1.
2.
In CSS
3.