3

我为我的 .html 页面添加了渐变背景。似乎可以在大多数浏览器中使用,但我想知道它是否是标准的并符合所有规则。

.css

html {
  /* fallback  */
  background-color: #65a5d1;

  /* Safari 4-5, Chrome 1-9 */
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#65a5d1));

  /* Safari 5.1, Chrome 10+ */
  background: -webkit-linear-gradient(top, #fff, #65a5d1);

  /* Firefox 3.6+ */
  background: -moz-linear-gradient(top, #fff, #65a5d1);

  /* IE 10 */
  background: -ms-linear-gradient(top, #fff, #65a5d1);

  /* Opera 11.10+ */
  background: -o-linear-gradient(top, #fff, #65a5d1);

  height: 900px;

}
4

1 回答 1

4

如果你想生成完全兼容的渐变,你可以查看Ultimate CSS Gradient Generator

这是它生成的输出:

/* Old browsers */
background: #1e5799;

/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMTAwJSIgeDI9IjEwMCUiIHkyPSIwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjMWU1Nzk5IiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iNTAlIiBzdG9wLWNvbG9yPSIjMjk4OWQ4IiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iNTElIiBzdG9wLWNvbG9yPSIjMjA3Y2NhIiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzdkYjllOCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);

/* FF3.6+ */
background: -moz-linear-gradient(45deg,  #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);

/* Chrome, Safari4+ */
background: -webkit-gradient(linear, left bottom, right top, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8));

/* Chrome10+,Safari5.1+ */
background: -webkit-linear-gradient(45deg,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);

/* Opera 11.10+ */
background: -o-linear-gradient(45deg,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);

/* IE10+ */
background: -ms-linear-gradient(45deg,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);

/* W3C */
background: linear-gradient(45deg,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);

/* IE6-8 fallback on horizontal gradient */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=1 );

如您所见,它会生成更多属性以涵盖更多情况。


如果你想支持 IE 9,你必须遵循这个......是的,我知道这很糟糕,但是......

使用 IE9 支持完整的多级渐变(使用 SVG):

为所有具有渐变的元素添加一个“渐变”类,并将以下覆盖添加到您的 HTML 以完成对 IE9 的支持:

<!--[if gte IE 9]>
  <style type="text/css">
    .gradient {
       filter: none;
    }
  </style>
<![endif]-->
于 2012-10-20T15:54:45.273 回答