在IE中显示渐变

时间:2011-11-09 17:50:58

标签: internet-explorer css

我们在IE中正确显示渐变时遇到问题。以下HTML在Chrome和其他浏览器中很好地显示了渐变,但在IE中显示的几乎是纯蓝色。非常感谢帮助!

<HTML>
    <HEAD>
        <STYLE type="text/css">
            body {
                /* Old browsers */
                background: #1e5799;
                /* IE9 SVG, needs conditional override of 'filter' to 'none' */
                background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjI0JSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcyJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZGI5ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
                /* FF3.6+ */
                background: -moz-linear-gradient(top,  #1e5799 0%, #ffffff 24%, #ffffff 72%, #7db9e8 100%);
                 /* Chrome,Safari4+ */
                background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(24%,#ffffff), color-stop(72%,#ffffff), color-stop(100%,#7db9e8));
                /* Chrome10+,Safari5.1+ */
                background: -webkit-linear-gradient(top,  #1e5799 0%,#ffffff 24%,#ffffff 72%,#7db9e8 100%); 
                /* Opera 11.10+ */
                background: -o-linear-gradient(top,  #1e5799 0%,#ffffff 24%,#ffffff 72%,#7db9e8 100%);
                /* IE10+ */
                background: -ms-linear-gradient(top,  #1e5799 0%,#ffffff 24%,#ffffff 72%,#7db9e8 100%);
                /* W3C */
                background: linear-gradient(top,  #1e5799 0%,#ffffff 24%,#ffffff 72%,#7db9e8 100%);
                /* IE6-8 */
                filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );
            }
        </style>
    </HEAD>
<BODY>
    <H1 >Testing Blue Gradient</H1>
</BODY>
</HTML>

3 个答案:

答案 0 :(得分:0)

试试这个:

body {
  background-color: #1e5799;
  background-image: -webkit-gradient(linear, left top, left bottom, from(#1e5799), to(#7db9e8)); 
  background-image: -webkit-linear-gradient(top, #1e5799, #7db9e8); 
  background-image:    -moz-linear-gradient(top, #1e5799, #7db9e8); 
  background-image:     -ms-linear-gradient(top, #1e5799, #7db9e8); 
  background-image:      -o-linear-gradient(top, #1e5799, #7db9e8); 
  background-image:         linear-gradient(top, #1e5799, #7db9e8);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#1e5799', EndColorStr='#7db9e8'); 
}

我在IE 6-9中测试过 - 工作正常。

CSS3 Please

答案 1 :(得分:0)

@zoltan对如何做css有一个很好的答案。另一种使用过滤器的方法是使用http://css3pie.com/。除了渐变之外,它还增加了圆角和框阴影。另外,它可以让你在同一个元素上完成所有三个。

behavior: url(/PIE.htc);

答案 2 :(得分:0)

将此用于IE:

filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#000000', endColorstr='#ffffff'); 
/* for IE */