CSS3 渐变在 firefox 和 IE 中不起作用(在 chrome 中起作用)

标签 css gradient

我为文本创建了一个渐变类。它在 google chrome 中运行良好,但在 firefox 和 internet explorer 中则不然。在这些浏览器中,我不希望在文本后面看到实际的背景渐变。

我创建了一个可以感知这种浏览器不同行为的 fiddle 。

https://jsfiddle.net/Lzhvsowq/

<h1 class="gradient_blue" style="font-size: 60px;">Lorem Ipsum Lorem Ipsum</h1>

.gradient_blue {
  color: #288cc7;
  display: inline-block;
  background-color: #288cc7;
  background-image: -webkit-linear-gradient(left, #288cc7 0%, #206e9b 100%);
  background-image: -o-linear-gradient(left, #288cc7 0%, #206e9b 100%);
  background-image: linear-gradient(to right, #288cc7 0%, #206e9b 100%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#288cc7', endColorstr='#206e9b', GradientType=1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

感谢任何帮助!

最佳答案

您正在使用仅 WebKit 功能,例如 -webkit-background-clip: text,这就是它仅适用于 Chrome、Safari 和 Opera 的原因。不幸的是,IE 或 Firefox 似乎没有类似的功能。

如果你想制作文本渐变,对于非 WebKit 浏览器来说最好的选择可能是使用 SVG gradients (jsfiddle here):

<h1 class="gradient_blue" style="font-size: 60px;">
<svg height="100%" width="100%">
      <defs>
        <linearGradient id="gradient" x1="0%" x2="100%" y1="0%" y2="0%">
          <stop offset="0%" style="stop-color:#288cc7;" />
          <stop offset="100%" style="stop-color:#206e9b;" />
        </linearGradient>
      </defs>
      <text fill="url(#gradient)" x="1%" y="30%">
         Lorem Ipsum Lorem Ipsum
      </text>
 </svg>
 </h1>

关于CSS3 渐变在 firefox 和 IE 中不起作用(在 chrome 中起作用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36789866/

相关文章:

html - 带 Canvas 菜单的 Bootstrap 导航栏

html - 为什么 normalize.css 不设置字体样式 : italic for <i> and <em> tags?

ios - 如何在 iOS 中创建从全彩到不透明度 0 的渐变?

html - 边框上的 CSS 渐变

ios - UInt32 颜色的渐变效果?

html - 防止元素在 Chrome 中跳来跳去

html - CSS/Sass 网格间隙没有响应

html - apache中目录列表的自动样式

css - 如何使 CSS 渐变看起来平滑?

css - 部分 div 而不是整个 div 的 Firefox css 线性渐变属性?