在Chrome/Safari和Firefox中,可以使用-webkit-gradient
和-moz-linear-gradient
属性。如何在IE9中进行类似的操作?
在Chrome/Safari和Firefox中,可以使用-webkit-gradient
和-moz-linear-gradient
属性。如何在IE9中进行类似的操作?
background: #fff;
background: -moz-linear-gradient(#fff, #000);
background: -webkit-linear-gradient(#fff, #000);
background: -o-linear-gradient(#fff, #000);
background: -ms-linear-gradient(#fff, #000);/*For IE10*/
background: linear-gradient(#fff, #000);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff', endColorstr='#000000');/*For IE7-8-9*/
height: 1%;/*For IE7*/
嗯,IE9还没有完成,但到目前为止,看来你需要使用SVG。我不知道IE9中是否支持-ms-gradient或梯度。另一个让我感到困扰的缺失是text-shadow。
background-color: #fff; /* Browsers without linear-gradient support */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fff), color-stop(100%, #000)); /* Chrome, Safari 4+ */
background-image: -webkit-linear-gradient(#fff 0%, #000 100%); /* Chrome 10+, Safari 5.1+ */
background-image: -moz-linear-gradient(#fff 0%, #000 100%); /* Fx 3.6+ */
background-image: linear-gradient(#fff 0%, #000 100%); /* W3C */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#ffffff', endColorstr='#000000')";
.gradient--test {
background-color: #fff; /* Browsers without linear-gradient support */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fff), color-stop(100%, #000)); /* Chrome, Safari 4+ */
background-image: -webkit-linear-gradient(#fff 0%, #000 100%); /* Chrome 10+, Safari 5.1+ */
background-image: -moz-linear-gradient(#fff 0%, #000 100%); /* Fx 3.6+ */
background-image: linear-gradient(#fff 0%, #000 100%); /* W3C */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#ffffff', endColorstr='#000000')";
}
.gradient--test {
width: 61.8%;
height: 200px;
}
<div class=gradient--test></div>
IE 9引入了供应商前缀-ms-filter
标记,符合标准,同时弃用了专有过滤器。
没有必要使用-o-
供应商前缀,也不需要使用-ms-
(因为IE 10是第一个支持渐变的IE,它支持W3C标准语法)。请参见http://caniuse.com/#feat=css-gradients
首选小写十六进制颜色值以获得更好的gzip压缩,并明确说明background-color
和background-image
而不是background
,因为这可能会导致在不支持线性渐变的浏览器中出现渲染错误。
大部分内容来自我的回答。