IE9 圆角和圆角CSS 背景渐变共存?
我在 IE9 中遇到了一个奇怪的事情,试图显示背景渐变。
基本上我将多个类应用于一个容器对象。
<div class="gradient corners"></div>
使用这个CSS。
.gradient {
background-color: #96A7C5;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.19, #6C86AD),
color-stop(0.6, #96A7C5)
);
background-image: -moz-linear-gradient(
center bottom,
#75A33A 19%,
#8DC447 60%
);
.corners {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
为了在 IE 中获得渐变,我将过滤器垃圾应用到我的 .gradient 类中。
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447', endColorstr='#75A33A');
这样,渐变就起作用了,但我的圆角消失了。
所以我尝试为过滤器声明添加一个条件。
<!--[if IE]>
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447', endColorstr='#75A33A');
<![endif]-->
这使我的角落恢复,但梯度消失了。
I came across a weird thing in IE9 trying to get a background gradient to display.
Basically I'm applying multiple classes to a container object.
<div class="gradient corners"></div>
Using this CSS.
.gradient {
background-color: #96A7C5;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.19, #6C86AD),
color-stop(0.6, #96A7C5)
);
background-image: -moz-linear-gradient(
center bottom,
#75A33A 19%,
#8DC447 60%
);
.corners {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
To get the gradient in IE, I apply the filter garbage to my .gradient class.
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447', endColorstr='#75A33A');
With that, the gradient works but my rounded corners go away.
So I tried putting in a conditional for the filter declaration.
<!--[if IE]>
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8DC447', endColorstr='#75A33A');
<![endif]-->
That brings back my corners but the gradient goes away.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 IE9 中,圆角的渐变效果会消失,因此目前最好的解决方案是添加一个额外的 div:
并隐藏 .corners 的溢出。
我推荐这个类似 Photoshop 的工具来创建跨浏览器渐变: http://www.colorzilla.com/gradient-editor/
这一个创建边框半径:
http://border-radius.com/
Gradient will go out for rounded corners in IE9, so the best solution for now to add one extra div:
and hide overflow for .corners
I recomend this Photoshop-like tool for creating cross-browser gradients: http://www.colorzilla.com/gradient-editor/
And this one to create border-radius:
http://border-radius.com/
您不需要
if IE
块。只需将所有 3 个(如果包含两个 IE,则为 4 个)规则放入样式声明中,浏览器将只选择它们理解的规则。
一个例子:
还应该注意的是,IE 中的渐变仅在元素
hasLayout
时才起作用(请参阅:http://reference.sitepoint.com/css/haslayout)you don't need the
if IE
block.just put all 3(4 if you include both IEs) rules in the style declaration, the browsers will only pick up the ones that they understand.
an example:
It should also be noted that gradients in IE will only work if the element
hasLayout
(See: http://reference.sitepoint.com/css/haslayout)这是解决 IE9 渐变与角问题的一个非常可靠的解决方法。
它使用 js 动态生成 SVG - 而且速度很快。
http://abouthalf.com/2011/10/ 04/updated-ie9-gradients-with-rounded-corners/
This is a pretty solid workaround for the IE9 gradients vs corners issue.
It uses js to generate an SVG on the fly - and it's fast.
http://abouthalf.com/2011/10/04/updated-ie9-gradients-with-rounded-corners/
圆角和滤镜不相配。对于 IE,我总是包含 http://css3pie.com 并使用它在 IE 中执行边框半径和渐变。示例 css 如下所示:
步骤:
rounded corners and filter don't go together. for IE i always include http://css3pie.com and use it to do border-radius and gradients in IE. a sample css looks like this:
The steps:
只需使用包装 div(圆角和溢出隐藏)来剪辑 IE9 的半径。简单,跨浏览器工作。 SVG 或 JS 是不必要的。
Just use a wrapper div (rounded & overflow hidden) to clip the radius for IE9. Simple, works cross-browser. SVG or JS are unnecessary.