CSS文本转换大写的所有大写 [英] CSS text-transform capitalize on all caps

查看:253
本文介绍了CSS文本转换大写的所有大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的HTML:

<a href="#" class="link">small caps</a> & 
<a href="#" class="link">ALL CAPS</a>

这是我的CSS:

.link {text-transform: capitalize;}

Small Caps & ALL CAPS

,我想输出为:

Small Caps & All Caps

有任何想法吗?

推荐答案

没有办法使用CSS,你可以使用PHP或Javascript。

There is no way to do this with CSS, you could use PHP or Javascript for this.

PHP示例:

$text = "ALL CAPS";
$text = ucwords(strtolower($text)); // All Caps

jQuery示例(现在是一个插件):

jQuery example (it's a plugin now!):

// Uppercase every first letter of a word
jQuery.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) + (c+1==val.length ? '' : ' ');
    }
    $(this).text(newVal);
  });
}

$('a.link').ucwords();​

这篇关于CSS文本转换大写的所有大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆