IE 中的对角渐变
有没有办法在 IE 中实现对角渐变?在 Chrome 中我可以做这样的事情:
body{
background-image:-webkit-gradient(
linear,
left top,
right bottom,
color-stop(0%,#f00),
color-stop(50%,#0f0),
color-stop(100%,#00f));
}
但这在 IE 中不起作用。
Is there a way to have a diagonal gradient in IE? In Chrome I could do something like this:
body{
background-image:-webkit-gradient(
linear,
left top,
right bottom,
color-stop(0%,#f00),
color-stop(50%,#0f0),
color-stop(100%,#00f));
}
but this doesn't work in IE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是可能的!尽管它在其他浏览器中的效果不如真正的对角渐变。
该解决方案有两个重要方面使其发挥作用:
z-index
值(一个在另一个顶部/前面)和不同渐变方向(一个水平,一个垂直)只需将具有垂直渐变的 div 位于具有水平渐变的 div 后面(反之亦然,这并不重要),并确保最上面的渐变的颜色不是不透明的。
结果如下所示(Internet Explorer 8):
和 CSS:
更新:
有关此过滤器的文档确实表明可以一起应用多个过滤器。然而,事实证明,应用多个梯度过滤器会导致仅应用最后一个过滤器,因此简单地将两个过滤器应用到一层是行不通的,需要两层。
Yes, it is possible! Although it does not work as well as a real diagonal gradient in other browswers.
There are two important aspects of this solution that make it work:
z-index
values (one on top of/in front of the other) and different gradient directions (one horizontal, one vertical)Simply place the div with the vertical gradient behind the div with the horizontal gradient (or vice-versa, it doesn't really matter), and make sure the coloring of the topmost gradient is not opaque.
The result looks like this (Internet Explorer 8):
And the CSS:
Update:
The documention on this filter does say that multiple filters may be applied together. However, as it turns out, applying more than one gradient filter results in only the last one being applied, so simply applying both filters to one layer doesn't work, and two layers are necessary.
不幸的是,简短的答案是,不,你可以't. Microsoft 的渐变过滤器是二进制的 - 仅从左到右或从上到下。
但是,您可以使用 CSS3 PIE 来执行您想要的操作。请记住,PIE 在 IE9 中对渐变的支持有些粗略,即使 IE7 和 8 可以工作,也可能工作或不工作(请参阅 他们的论坛了解更多信息)。
The short answer is, unfortunately, no, you can't. Microsoft's gradient filter is binary - only left to right or top to bottom.
You might, however, be able to use CSS3 PIE to do what you want. Keep in mind that PIE's support for gradients in IE9 is somewhat sketchy, though, and may or may not work, even if IE7 and 8 do (see their forums for some more info).