How to Capitalize first letter only using CSS in each case

后端 未结 5 1833
礼貌的吻别
礼貌的吻别 2021-02-13 04:10

I want to Capitalize first letter only and other should be small using CSS

String is:

SOMETHING BETTER 
sOMETHING bETTER
Something bett         


        
5条回答
  •  死守一世寂寞
    2021-02-13 04:57

    You can try a combination of this answer and some javascript (using jQuery)

    HTML:

    SOMETHING BETTER SOMETHING BETTER SOMETHING BETTER

    JAVASCRIPT:

    $('.capitalize').each(function(){
        var text = this.innerText;
        var words = text.split(" ");
        var spans = [];
        var _this = $(this);
        this.innerHTML = "";
        words.forEach(function(word, index){
            _this.append($('', {text: word}));
        });
    });
    

    CSS:

    .capitalize {
        text-transform: lowercase;
    }
    
    .capitalize span {
        display: inline-block;
        padding-right: 1em  
    }
    
    .capitalize span:first-letter {
        text-transform: uppercase !important;
    }
    

    Demo: http://jsfiddle.net/maniator/ZHhqj/

提交回复
热议问题