5

这个使用 SASS 和 Compass 完成的渐变在任何版本的 Internet Explorer 中都不起作用:

@include background-image(linear-gradient(left, rgba(241,236,236,0.95), rgba(241,236,236,0.9), rgba(241,236,236,0.85), rgba(241,236,236,0.8), rgba(241,236,236,0.75), rgba(241,236,236,0.4)));

它转换为这个 CSS:

  background-image: -webkit-gradient(linear, 0% 50%, 100% 50%, color-stop(0%, rgba(241, 236, 236, 0.95)), color-stop(20%, rgba(241, 236, 236, 0.9)), color-stop(40%, rgba(241, 236, 236, 0.85)), color-stop(60%, rgba(241, 236, 236, 0.8)), color-stop(80%, rgba(241, 236, 236, 0.75)), color-stop(100%, rgba(241, 236, 236, 0.4)));
  background-image: -webkit-linear-gradient(left, rgba(241, 236, 236, 0.95), rgba(241, 236, 236, 0.9), rgba(241, 236, 236, 0.85), rgba(241, 236, 236, 0.8), rgba(241, 236, 236, 0.75), rgba(241, 236, 236, 0.4));
  background-image: -moz-linear-gradient(left, rgba(241, 236, 236, 0.95), rgba(241, 236, 236, 0.9), rgba(241, 236, 236, 0.85), rgba(241, 236, 236, 0.8), rgba(241, 236, 236, 0.75), rgba(241, 236, 236, 0.4));
  background-image: -o-linear-gradient(left, rgba(241, 236, 236, 0.95), rgba(241, 236, 236, 0.9), rgba(241, 236, 236, 0.85), rgba(241, 236, 236, 0.8), rgba(241, 236, 236, 0.75), rgba(241, 236, 236, 0.4));
  background-image: linear-gradient(left, rgba(241, 236, 236, 0.95), rgba(241, 236, 236, 0.9), rgba(241, 236, 236, 0.85), rgba(241, 236, 236, 0.8), rgba(241, 236, 236, 0.75), rgba(241, 236, 236, 0.4));

那么你如何用 IE 来解决这个问题呢?

我正在使用 Internet Explorer 11 对其进行测试。我需要它在 IE9+ 上工作

正如下面的帮助,我现在找到了涵盖 IE10+ 的答案,这对我有帮助:

background: -ms-linear-gradient(left, rgba(241,236,236,0.95), rgba(241,236,236,0.9), rgba(241,236,236,0.85), rgba(241,236,236,0.8), rgba(241,236,236,0.75), rgba(241,236,236,0.4)); /* IE10+ */

在我为 IE9 尝试以下但没有工作之后:

filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f1ecec', endColorstr='#fffafa',GradientType=1 );

我可以用什么来掩盖烦人的 IE9?

4

2 回答 2

3

您必须为 IE6-9 使用过滤器,如下所示:

filter: progid:DXImageTransform.Microsoft.gradient(...)

对于 IE10+

-ms-linear-gradient

我相信 IE6-9 可能只支持 2 个色标。我能给你的最好的帮助是:

http://www.colorzilla.com/gradient-editor/

这个东西的神奇工具:)

如果你将你的 CSS “导入”到你得到的工具中:

/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2YxZWNlYyIgc3RvcC1vcGFjaXR5PSIwLjk1Ii8+CiAgICA8c3RvcCBvZmZzZXQ9IjgwJSIgc3RvcC1jb2xvcj0iI2YxZWNlYyIgc3RvcC1vcGFjaXR5PSIwLjc1Ii8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmMWVjZWMiIHN0b3Atb3BhY2l0eT0iMC40Ii8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, rgba(241,236,236,0.95) 0%, rgba(241,236,236,0.75) 80%, rgba(241,236,236,0.4) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(241,236,236,0.95)), color-stop(80%,rgba(241,236,236,0.75)), color-stop(100%,rgba(241,236,236,0.4))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(241,236,236,0.95) 0%,rgba(241,236,236,0.75) 80%,rgba(241,236,236,0.4) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(241,236,236,0.95) 0%,rgba(241,236,236,0.75) 80%,rgba(241,236,236,0.4) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(241,236,236,0.95) 0%,rgba(241,236,236,0.75) 80%,rgba(241,236,236,0.4) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(241,236,236,0.95) 0%,rgba(241,236,236,0.75) 80%,rgba(241,236,236,0.4) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f2f1ecec', endColorstr='#66f1ecec',GradientType=0 ); /* IE6-8 */

使用 IE9(使用 SVG)支持完整的多级渐变。为所有具有渐变的元素添加一个“渐变”类,并将以下覆盖添加到您的 HTML 以完成对 IE9 的支持:

<!--[if gte IE 9]>
  <style type="text/css">
    .gradient {
       filter: none;
    }
  </style>
<![endif]-->

...甚至是 SCSS 版本

// needs latest Compass, add '@import "compass"' to your scss
@include filter-gradient(#f2f1ecec, #66f1ecec, vertical); // IE6-8
// IE9 SVG, needs conditional override of 'filter' to 'none'
$experimental-support-for-svg: true;
@include background-image(linear-gradient(top,  rgba(241,236,236,0.95) 0%,rgba(241,236,236,0.75) 80%,rgba(241,236,236,0.4) 100%));

这是您导入的 css 的链接,它应该可以帮助您:http ://www.colorzilla.com/gradient-editor/#f1ecec+0,f1ecec+100&0.95+0,0.75+80,0.4+100;Custom

于 2013-11-15T09:57:29.910 回答
2

This dont work in IE11

background-image: linear-gradient(top, #ff0000,#ffff00);

This work and show like then webkit version

background-image: linear-gradient(180deg, #ff0000,#ffff00);

The webkit also support the ...deg mode, but dont work as the explorer does, this is the equivalent in webkit.

-webkit-linear-gradient(270deg, #ff0000,#ffff00);

Note: Chrome understand the no webkit version as explorer does.

于 2014-04-30T12:32:34.127 回答