CSS 如何为 IE8 应用线性渐变
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17099650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply linear gradient for IE8
提问by smons
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:-
线性渐变适用于除 IE8 之外的所有浏览器。
我补充说progid:DXImageTransform.Microsoft.gradient
......这确实给了它一些梯度,但预期的结果是不同的。
代码:-
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?
我如何使这个渐变线性?
回答by lukeocom
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.
我用来创建线性渐变的css如下。在 IE8 中也能正常工作。似乎与您的唯一区别是我将渐变类型设置为 1(水平),而不是 0(垂直),并且我使用了不同的颜色。
html
html
<div></div>
css
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 */
}
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.
另一个问题是您使用的颜色接近白色,因此渐变效果并不那么明显。尝试更改为更明显的起始颜色,例如 #ff000,以查看渐变是否真正起作用。您还有一个重复的背景颜色值。