Linear-gradient not working in IE 11

2020-03-05 02:12发布

问题:

I have a css rule that works fine in chrome, firefox and used to work in IE. Now my seemingly valid css is not working.

.s-tour {
/*border-radius: 5px;*/
margin: 0 auto;
width: 250px;
height: 200px;
line-height: 100px;
font-weight: 600;
font-size: 18px;
box-shadow: 0 0 7px rgba(1, 1, 1, .8);
border: solid thin #555;
color: #E0E0E0;
background: #555;
background-image: linear-gradient(to bottom, #555 0%, #eee 100%);
background-image:-webkit-linear-gradient(top, #777, #666);
background-image: -ms-linear-gradient(top,#555555 0%,#666666 100%);
background-image:-o-linear-gradient(top, #777, #666);
background-image:-moz-linear-gradient(top, #777, #666);
}

I feel like both background-image: linear-gradient(to bottom, #555 0%, #eee 100%); or -ms-background-image: linear-gradient(top,#555555 0%,#666666 100%); should be working for IE 11 yet the the IE inspector puts a fuzzy red line under it and anything else I try.

I checked a working gradient on a google page and background-image: -ms-linear-gradient(top,#f5f5f5,#f1f1f1); was working fine, yet even that exact line would not work on my site.

I've tried all variations I can think of in terms of property,prefix and values, including every relevant answer on stack overflow and am now stumped, wondering if it is a DOM issue or bug or something simple.

回答1:

try adding this line to the end of your class:

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#555555, endColorstr=#666666);


回答2:

So the problem I really had was that I was not telling IE to render the page using the latest standards of css. Adding <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> to the <head> block fixed most of my problems.



回答3:

What has worked for me in IE11 is to correctly use the CSS3 linear-gradient property (http://www.w3schools.com/css/css3_gradients.asp)

An example:

background: linear-gradient(to bottom, #FFF 0%, #EEE 100%);

After that I didn't need to use any meta tags or old filter syntax.



回答4:

Using 180deg instead of top solved the same problem for me.

Previously tried filter and already had <meta http-equiv="X-UA-Compatible" content="IE=Edge" />