CSS text-transform capitalize on all caps

2019-01-03 14:53发布

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?

标签: css
15条回答
等我变得足够好
2楼-- · 2019-01-03 15:48

captialize only effects the first letter of the word. http://www.w3.org/TR/CSS21/text.html#propdef-text-transform

查看更多
够拽才男人
3楼-- · 2019-01-03 15:48

I was not able to comment for Harmen because of lack of reputation so writing again the same answer of harmen. I have added LowerCase() to the answer so it can convert "ALL CAPS" to "All Caps".

$.fn.ucwords = function() {
return this.each(function(){
var val = $(this).text(), newVal = '';
val = val.split(' ');

for(var c=0; c < val.length; c++) {newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length).toLowerCase() + (c+1==val.length ? '' : ' ');
}
$(this).text(newVal);  
});
 $('a.link').ucwords();​ 
查看更多
Rolldiameter
4楼-- · 2019-01-03 15:51

Convert with JavaScript using .toLowerCase() and capitalize would do the rest.

查看更多
登录 后发表回答