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?
Interesting question!
capitalize
transforms every first letter of a word to uppercase, but it does not transform the other letters to lowercase. Not even the:first-letter
pseudo-class will cut it (because it applies to the first letter of each element, not each word), and I can't see a way of combining lowercase and capitalize to get the desired outcome.So as far as I can see, this is indeed impossible to do with CSS.
@Harmen shows good-looking PHP and jQuery workarounds in his answer.
You can do it with css first-letter! eg I wanted it for the Menu:
It only runs with block elements - therefore the inline-block!
If the data is coming from a database, as in my case, you can lower it before sending it to a select list/drop down list. Shame you can't do it in CSS.
There is no way to do this with CSS, you could use PHP or Javascript for this.
PHP example:
jQuery example (it's a plugin now!):
You can almost do it with:
It will give you the output:
After researching a lot I found jquery function/expression to change text in first letter in uppercase only, I modify that code accordingly to make it workable for input field. When you will write something in input field and then move to another filed or element, the text of that field will change with 1st-letter capitalization only. No matter user type text in complete lower or upper case capitalization:
Follow this code:
Step-1: Call jquery library in html head:
Step-2: Write code to change text of input fields:
Step-3: Create HTML input fields with same id's you use in jquery code like:
The id of this input field is: edit-submitted-first-name (It using in jquery code in step-2)
**Result: Make sure the text will change after you move your focus from that input field at another element. Because we using focus out event of jquery here. Result should like this: User Type: "thank you" it will change with "Thank You". **
Best of luck