smons
smons

Reputation: 485

How to apply linear gradient for IE8

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 );}    

How do I make this gradient linear?

Upvotes: 6

Views: 21559

Answers (1)

lukeocom
lukeocom

Reputation: 3243

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 */
    }

http://jsfiddle.net/yAxbJ/

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.

Upvotes: 5

Related Questions