CSS3是否可以添加文本渐变呢?

时间:2011-07-03 17:47:42

标签: css css3

我正在寻找在文字中添加渐变。关于这一点,净投注有quick tips。但它仅适用于webkit浏览器。由于这是相当古老的帖子,我正在检查是否有任何跨浏览器解决方案(忽视ie)。

我知道如何使用背景渐变图像

1 个答案:

答案 0 :(得分:7)

我知道在Firefox中使用它的唯一方法是通过SVG,遗憾的是它有点笨拙。好的部分是应该在Opera和IE9中工作(未经测试)。如果doctype被声明为XHTML并且作为XML(ugh)使用,则可以在Firefox 3.6中使用。

<svg height="200" width="500">
  <defs>
    <linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
      <stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:1"/>
      <stop offset="100%" style="stop-color:rgb(60,60,60); stop-opacity:1"/>
    </linearGradient>
  </defs>
  <text x="0" y="150" font-family="Arial Black, Arial" font-size="55" fill="url(#gradient)" letter-spacing="-1" class="svg_text">
    NICE GRADIENT
  </text>
</svg>

在JSFiddle上查看它 http://jsfiddle.net/sHaWW/