CSS for changing color of last word in h1

前端 未结 10 2444
遇见更好的自我
遇见更好的自我 2020-11-29 09:31

I have a website that I am developing using CSS3 and I have h1 tag for the title:

main title

Now I want t

10条回答
  •  死守一世寂寞
    2020-11-29 09:47

    This is not possible with pure CSS. However you can use lettering.js to get a ::last-word selector. CSS-Tricks has an excelent article on this: CSS-Tricks: A call for nth-everything. You can then do the following:

    h1 {
      color: #f00;
    }
    
    /* EDIT: Needs lettering.js. Please read the complete post,
     * before downvoting. Instead vote up. Thank you :)
     */
    h1::last-word {
      color: #00f;
    }
    

提交回复
热议问题