css字体特效,渐变颜色+动画效果

css属性中有一个background-clip,用于设置绘图的背景,它的值可以是content-box,padding-box,border-box,text,其中text就是把颜色绘制到文字上,还有一个属性是text-fill-color,它也是设置对象中文字的填充颜色,和color作用一样,它的优先级比color大,还有就是他的兼容性不太好,只适用于谷歌。靠这两个属性我们就可以设置好看的字体

  1. <style>
  2. .text{-webkit-background-clip: text;
  3. background-clip: text;
  4. background-image:linear-gradient(rgb(255,255,0),rgb(0,255,255));
  5. font-size: 20px;
  6. width:120px;
  7. -webkit-text-fill-color: transparent;
  8. }
  9. </style>
  10. <body>
  11. <p class="text">1234567</p>
  12. </body>

20200414194559284.png

就是这样,再配合动画可以做出更好的效果

  1. <style>
  2. .text{-webkit-background-clip: text;
  3. width: 200%;
  4. background-clip: text;
  5. background-image:linear-gradient(-45deg,rgb(255,255,0),rgb(0,255,255));
  6. font-size: 20px;
  7. width:120px;
  8. animation: shine 2s infinite;
  9. background-blend-mode: hard-light;
  10. background-size: 200%;
  11. color: white;
  12. -webkit-text-fill-color: transparent;
  13. }
  14. @keyframes shine {
  15. from {
  16. background-position: 100%;
  17. }
  18. to {
  19. background-position: 0;
  20. }
  21. }
  22. </style>
  23. <body>
  24. <p class='text'>123456</p>
  25. </body>

background-blend-mode是背景层颜色的混合模式,hard-height是高亮,这样子字体颜色就会从左到右变换

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/185
0 评论
3.6k

发表评论

!