html – 如何在CSS中使用渐变作为字体颜色?

前端之家收集整理的这篇文章主要介绍了html – 如何在CSS中使用渐变作为字体颜色?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在CSS中使用渐变作为字体颜色,而不使用图像?我想支持Firefox.

我使用这个代码,但Firefox不支持

  1. <div class="text1"> Gradient Text</div>
  2.  
  3. .text1
  4. {
  5. font-size: 40px;
  6. background: -webkit-linear-gradient(#0F3,#F00);
  7. -webkit-background-clip: text;
  8. -webkit-text-fill-color: transparent;
  9. }

解决方法

您可以使用位于彼此顶部的多个跨度,并为其中的每一个分配不同的高度和颜色.它真的很丑的编码明智,但它的作品.
http://jsfiddle.net/7yBNv/

文本选择行为有点时髦,但不是太糟糕.并复制几个条目(取决于选择哪一层)所以我会说你最好用svg来解决这个问题.

(我从这里得到答案,查看更多详情:http://www.bagnall.co.uk/gradient_text.asp)

HTML:

  1. <h1 class="Gradient">Sample Gradient Text (h1)
  2. <span class="G1" aria-hidden="true">Sample Gradient Text (h1)</span>
  3. <span class="G2" aria-hidden="true">Sample Gradient Text (h1)</span>
  4. <span class="G3" aria-hidden="true">Sample Gradient Text (h1)</span>
  5. <span class="G4" aria-hidden="true">Sample Gradient Text (h1)</span>
  6. <span class="G5" aria-hidden="true">Sample Gradient Text (h1)</span>
  7. </h1>

CSS:

  1. .Gradient{
  2. position: relative;
  3. overflow: hidden;
  4. height: 28px;
  5. }
  6. .Gradient,.Gradient .G1,.Gradient .G2,.Gradient .G3,.Gradient .G4,.Gradient .G5{
  7. height: 28px;
  8. position: absolute;
  9. margin: 0;
  10. top: 0px;
  11. left: 0px;
  12. color: #4a778b;
  13. font-family: century gothic,helvetica,arial;
  14. font-size: 23px;
  15. font-weight: normal;
  16. overflow: hidden;
  17. }
  18. .Gradient{
  19. position: relative;
  20. }
  21. .Gradient .G5{
  22. height: 10px;
  23. color: #81a4b4;
  24. z-index: 6;
  25. }
  26. .Gradient .G4{
  27. height: 13px;
  28. color: #789eae;
  29. z-index: 5;
  30. }
  31. .Gradient .G3{
  32. height: 16px;
  33. color: #6f96a6;
  34. z-index: 4;
  35. }
  36. .Gradient .G2{
  37. height: 19px;
  38. color: #618a9c;
  39. z-index: 3;
  40. }
  41. .Gradient .G1{
  42. height: 22px;
  43. color: #547f92;
  44. z-index: 2;
  45. }

猜你在找的HTML相关文章