简体   繁体   English

背景图像渐变不与ie9一起使用

[英]Background image gradient not working with ie9

Seems that the below code doesn't work with ie9. 似乎以下代码不适用于ie9。 Is there a workaround? 有解决方法吗? Thanks 谢谢

.orangeback {
/* IE10 Consumer Preview */ 
background-image: -ms-linear-gradient(top, #FF6900 0%, #FF8214 100%);

/* Mozilla Firefox */ 
background-image: -moz-linear-gradient(top, #FF6900 0%, #FF8214 100%);

/* Opera */ 
background-image: -o-linear-gradient(top, #FF6900 0%, #FF8214 100%);

/* Webkit (Safari/Chrome 10) */ 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #FF6900), color-stop(1, #FF8214));

/* Webkit (Chrome 11+) */ 
background-image: -webkit-linear-gradient(top, #FF6900 0%, #FF8214 100%);

/* W3C Markup, IE10 Release Preview */ 
background-image: linear-gradient(to bottom, #FF6900 0%, #FF8214 100%);
}

Try 尝试

filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff', endColorstr='#000000');/*For IE7-8-9*/

Let me know if it works. 如果有效,请告诉我。

This is pretty close: 这非常接近:

filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ff6900', endColorstr='#ff8214',GradientType=0 );

This works in IE6+. 这适用于IE6 +。

Or, for JUST IE9, you can replace it with an SVG by using the following styles, if the filter option doesn't float your boat: 或者,对于JUST IE9,如果filter选项不浮动您的船,您可以使用以下样式将其替换为SVG:

Add to .orangeback : 添加到.orangeback

background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmNjkwMCIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZjgyMTQiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);

Also add .ie9-gradient class to these elements, and add the following before the closing head tag: 还要为这些元素添加.ie9-gradient类,并在结束head标记之前添加以下内容:

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

To use the SVG polyfill for CSS3 gradients in IE9 you need to disable filter, so this code retains the filter gradient fallback for IE6-8 and uses SVG for IE9. 要在IE9中使用SVG polyfill用于CSS3渐变,您需要禁用过滤器,因此此代码保留IE6-8的filter渐变回退并使用SVG用于IE9。

In your case, there is not really a need to use the SVG polyfill for IE9 because you are using a normal 2 color linear gradient. 在您的情况下,实际上不需要为IE9使用SVG polyfill,因为您使用的是普通的2色线性渐变。 If you had a more complex gradient the second solution would probably be preferable, but for your purposes just using the filter solution should work fine. 如果你有一个更复杂的梯度,第二个解决方案可能更可取,但为了你的目的,只使用filter解决方案应该工作正常。

Use this (or a CSS preprocessor) and never worry about CSS3 gradients again: Colorzilla Gradient Generator 使用此(或CSS预处理器),再也不用担心CSS3渐变: Colorzilla Gradient Generator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM