target first letter of each word in css

前端 未结 2 1766
感情败类
感情败类 2020-12-20 05:01

I need to change size, color, and weight of every first letter of each word. I am not talking about Capitalize each first letter. I mean that target first letter and apply s

相关标签:
2条回答
  • 2020-12-20 05:45

    You should wrap every single word with a tag and use ::first-letter CSS selector .

    Also, note that this selector does not work on inline elements. If you want to use it with an inline element, such a <span>, make sure you set display:inline-block (see here for more details: https://stackoverflow.com/a/7631782/11298742)

    example :

    p span { display: inline-block; font-family: 'Roboto', sans-serif }
    p span::first-letter {
        color: red;
        font-weight: bold;
    }
    <p><span>Lorem</span> <span>ipsum</span> <span>dolor</span> <span>sit</span> <span>amet</span></p>

    0 讨论(0)
  • 2020-12-20 05:48

    AFAIK to achieve this you will have to write the 1st letter in seperate tag like label or div or p tag and apply css to this tag and put rest letters in normal tag

    UPDATE: As per your comment if you are getting sentence from text field you will have to make a Javascript that will loop through all words and with the help of substr find the 1st character of each word and appy css by putting it in a tag and keep rest letters outside the tag then replace final output with original text

    0 讨论(0)
提交回复
热议问题