How can I capitalize the first letter of each word in CSS?

前端 未结 3 1011
死守一世寂寞
死守一世寂寞 2021-01-14 00:01

I am trying to capitalize the first letter of each word. I did search for it but i did not get it, is it possible in CSS?

My Code currently works for the first lette

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 00:40

    There is no way of doing this with CSS alone if the text in the element is in ALL CAPS already, the capitalize style will not work as it only changes the case to uppercase. example:

    p {
      text-transform: capitalize;
     }

    some text

    Some text

    SOME TEXT

    sOME tExt

    If the entire text is already in lowercase, you can style it with the element{ text-transform: capitalize; }, but if elements are already in uppercase, the text-transform: capitalize; will not accomplish a "title caps". You will need to insert a javascript element.toLowerCase(); on the element in question then have CSS work its magic.

    However, looking at the code provided and your question, the text is already doing what you want and the css selectors don't match the element so I'm not entirely certain what you are trying to accomplish.

提交回复
热议问题