如何在指南针中使用IE9、IE8、IE7和Opera制作跨浏览器渐变混合?

发布于 2024-12-27 15:50:13 字数 4773 浏览 2 评论 0原文

我想为所有浏览器制作mixin,包括IE9、IE8、IE7和Opera。

代码

http://www.colorzilla.com/gradient-editor/ 生成它生成的

background: #1e5799; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iIzI5ODlkOCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUxJSIgc3RvcC1jb2xvcj0iIzIwN2NjYSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZGI5ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top,  #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-8 */

对于 IE9,我们需要设置 filter:none

支持 IE9 的完整多级渐变(使用 SVG)。添加一个 “gradient”类到所有具有渐变的元素,并添加 对 HTML 进行以下覆盖以完成 IE9 支持:


Compass 有最新的渐变模块 http: //compass-style.org/reference/compass/css3/images/ 我们可以在调用 $experimental-support-for-svg: true 后使用它,例如像这样

.gradient {@include linear-gradient(#000000, #ff0000)}

使用 给出这样的输出

.gradient {
  background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2ZmMDAwMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
  background-size: 100%;
  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #000000), color-stop(100%, #ff0000));
  background-image: -webkit-linear-gradient(#000000, #ff0000);
  background-image: -moz-linear-gradient(#000000, #ff0000);
  background-image: -o-linear-gradient(#000000, #ff0000);
  background-image: -ms-linear-gradient(#000000, #ff0000);
  background-image: linear-gradient(#000000, #ff0000);
}

如果我们 将指南针图像代码与colorzilla代码进行比较

我的问题:

  1. background-size: 100%;有什么好处?
  2. 使用 background-image 代替 background 有什么好处?
  3. 有没有办法将 filter:none 添加到仅适用于 IE9 的元素 罗盘?
  4. 如何在指南针中也获得 IE6-8 兼容代码,如下 过滤器: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );

I want to make mixin for all browser including IE9 IE9, IE8, IE7 and Opera.

Like http://www.colorzilla.com/gradient-editor/ generate the code

it generate

background: #1e5799; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iIzI5ODlkOCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUxJSIgc3RvcC1jb2xvcj0iIzIwN2NjYSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZGI5ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top,  #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(top,  #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-8 */

And for IE9 We need to set filter:none

Support for full multi-stop gradients with IE9 (using SVG). Add a
"gradient" class to all your elements that have a gradient, and add
the following override to your HTML to complete the IE9 support:

<!--[if gte IE 9]>
  <style type="text/css">
    .gradient {
       filter: none;
    }
  </style>
<![endif]-->

Compass has latest module for gradient http://compass-style.org/reference/compass/css3/images/ which we can use after calling $experimental-support-for-svg: true and for example use like this

.gradient {@include linear-gradient(#000000, #ff0000)}

Which gives output like this

.gradient {
  background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2ZmMDAwMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
  background-size: 100%;
  background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #000000), color-stop(100%, #ff0000));
  background-image: -webkit-linear-gradient(#000000, #ff0000);
  background-image: -moz-linear-gradient(#000000, #ff0000);
  background-image: -o-linear-gradient(#000000, #ff0000);
  background-image: -ms-linear-gradient(#000000, #ff0000);
  background-image: linear-gradient(#000000, #ff0000);
}

if we compare compass Image code this to colorzilla code

  • it's missing which is for IE6-8

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

  • and for older browsers background: #1e5799; /* Old browsers */
  • and it's using background-image instead background
  • and it has one extra property background-size: 100%;
  • and there is no instruction on this page
    http://compass-style.org/reference/compass/css3/images/ for how to
    solve filter:none required for IE9.

My questions:

  1. What is the benefit of background-size: 100%;?
  2. What is the benefit of using background-image instead background?
  3. Is there a way to add filter:none to the element only for IE9 in
    Compass?
  4. How to get IE6-8 compatible code too in compass like this filter:
    progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799',
    endColorstr='#7db9e8',GradientType=0 );
    ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘香 2025-01-03 15:50:13

background-size: 100%有什么好处?

使用背景图像代替背景有什么好处?

SVG 图像是背景图像,该属性的内容是以编程方式生成的图像。为了保持一致,Compass 使用背景图像。此外,指定背景图像可以允许编码器指定不会被 mixin 破坏的背景颜色。

设置背景大小可确保图像实际拉伸以填充元素的空间,而不是图像本身的大小。

有没有办法在Compass中仅针对IE9的元素添加filter:none?

如何在指南针中获取 IE6-8 兼容代码,如下过滤器: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );?

这两个选项都有三个选项:

  1. 扩展 mixin/编写自己的 mixin。包含的 mixins 只是存储在 Compass 的安装位置中的文件,因此您可以随时编辑它们,或使用它们来创建您自己的 mixins。
  2. 将 CSS3 PIE 与 Compass 结合使用。
  3. 将 IE 特定代码放入一个或更多特定于 IE 的样式表(如果 PIE 不可行,这是我的首选方法,因为它对 CSS 进行沙箱处理,因此您无需进行修改即可获取一个版本或另一个版本来忽略给定的 CSS 行)。

What is the benefit of background-size: 100%;?

What is the benefit of using background-image instead background?

SVG images are background images, and the contents of that property is a programatically generated image. To keep it consistent, Compass uses the background image. Additionally, specifying background-image can allow the coder to specify a background-color that won't get nuked by the mixin.

Setting background-size ensures that the image actually stretches to fill the space of the element, instead of being the size of the image itself.

Is there a way to add filter:none to the element only for IE9 in Compass?

How to get IE6-8 compatible code too in compass like this filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );?

There are three options to both of these:

  1. Extend the mixin/write your own mixin. The included mixins are just files that are stored in Compass's install location, so you can always edit them, or use them to create your own mixins.
  2. Use CSS3 PIE with Compass.
  3. Put the IE-specific code into one or more IE-specific stylesheets (this is my preferred method if PIE isn't an option, as it sandboxes the CSS, so you don't have to do hacks to get one version or another to ignore a given line of CSS).
薯片软お妹 2025-01-03 15:50:13

首先在你的 _base.scss 中尝试一下

@import "compass/support";
$legacy-support-for-ie7: true;
$legacy-support-for-ie8: true;
$experimental-support-for-microsoft: true;
$experimental-support-for-pie: false;
$experimental-support-for-svg: true;

然后添加

@import filter-gradient($start-color, $end-color, $orientation)

First of all give these a try in your _base.scss

@import "compass/support";
$legacy-support-for-ie7: true;
$legacy-support-for-ie8: true;
$experimental-support-for-microsoft: true;
$experimental-support-for-pie: false;
$experimental-support-for-svg: true;

Then add in

@import filter-gradient($start-color, $end-color, $orientation)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文