Gradient colors in Internet Explorer

2019-01-12 21:16发布

I know that Internet Explorer has some proprietary extensions so that you can do things like create divs with a gradient background. I can't remember the element name or it's usage. Does anyone have some examples or links?

10条回答
走好不送
2楼-- · 2019-01-12 21:55

Two things I discovered while struggling with IE 9 gradient.

  1. The -ms-filter did not work for me. I had to use simply filter.
  2. I had to add height: 100% to my class for IE to use the gradient.
查看更多
萌系小妹纸
3楼-- · 2019-01-12 21:57

Just thought I'd add this useful link: http://css3please.com/

Shows how to get gradients working in all browsers.

查看更多
Evening l夕情丶
4楼-- · 2019-01-12 21:59

The filter style should work for IE8 and IE9.

.gradientClass
{
  filter:  progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#e6e6e6', endColorstr='#CCCCCC');       
}
查看更多
Lonely孤独者°
5楼-- · 2019-01-12 22:02

The code I use for all browser gradients:

background: #0A284B;
background: -webkit-gradient(linear, left top, left bottom, from(#0A284B), to(#135887));
background: -webkit-linear-gradient(#0A284B, #135887);
background: -moz-linear-gradient(top, #0A284B, #135887);
background: -ms-linear-gradient(#0A284B, #135887);
background: -o-linear-gradient(#0A284B, #135887);
background: linear-gradient(#0A284B, #135887);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0A284B', endColorstr='#135887');
zoom: 1;

You will need to specify a height or zoom: 1 to apply hasLayout to the element for this to work in IE.


Update:

Here is a LESS Mixin (CSS) version for all you LESS users out there:

.gradient(@start, @end) {
    background: mix(@start, @end, 50%);
    filter: ~"progid:DXImageTransform.Microsoft.gradient(startColorStr="@start~", EndColorStr="@end~")";
    background: -webkit-gradient(linear, left top, left bottom, from(@start), to(@end));
    background: -webkit-linear-gradient(@start, @end);
    background: -moz-linear-gradient(top, @start, @end);
    background: -ms-linear-gradient(@start, @end);
    background: -o-linear-gradient(@start, @end);
    background: linear-gradient(@start, @end);
    zoom: 1;
}
查看更多
登录 后发表回答