本文介绍了如何为IE8应用线性渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

线性渐变适用于除IE8之外的所有浏览器。

我添加了 progid:DXImageTransform.Microsoft.gradient ...这确实给了它一些但是预期结果不同。

代码: -

Linear gradient works fine for all browsers except IE8.
I added progid:DXImageTransform.Microsoft.gradient...this did give it some gradient however expected result is different.
Code:-

div{
height:500px;width:500px; 
background-size: 50px 50px;
background-color: #DDEEEE;
background-image: -webkit-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
background-image: -moz-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
background-image: -ms-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
background-image: -o-linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
background-image: linear-gradient(rgba(255, 255, 255, .2) 50%, transparent 50%, transparent);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#DDEEEE',GradientType=0 );}    

如何使此渐变线性?

推荐答案

创建线性渐变如下。在IE8也很好。似乎和你唯一的区别是我将gradientType设置为1(水平),而不是0(垂直),并使用不同的颜色。

The css I use to create a linear gradient is as follows. Works fine in IE8 too. Seems the only difference to yours is I set a gradientType to 1 (horizontal), not 0 (vertical), and I use distinct colours.

html

<div></div>

css

div{width:400px;height:200px;
    /*gradient background color */
    background: #0071a0; /* Old browsers */
    background: -moz-linear-gradient(left,  #0071a0 1%, #ff0000 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right top, color-stop(1%,#0071a0), color-stop(100%,#ff0000)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(left,  #0071a0 1%,#00a3ca 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(left,  #0071a0 1%,#ff0000 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(left,  #0071a0 1%,#ff0000 100%); /* IE10+ */
    background: linear-gradient(to right,  #0071a0 1%,#ff0000 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0071a0', endColorstr='#ff0000',GradientType=1 ); /* IE6-9 */
    }

另一个问题是您使用接近白色的颜色,因此梯度效应不明显。尝试更改为更明显的起始颜色,例如#ff000,以查看渐变是否实际上首先工作。此外,您有一个重复的背景颜色值。

The other issue is that you are using close to white colours, so the gradient effect isnt that noticeable. Try changing to a more distinct starting colour such as #ff000 to see if the gradient is actually working first. Also you have a duplicate background-color value.

这篇关于如何为IE8应用线性渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 18:06