我想要的背景图片不被显示在IE。我怎么做? [英] I want the background picture not to be displayed in the IE. How do I do that?
问题描述
下面是CSS,我想背景图片不显示在IE浏览器。相反,我只是想显示的背景色。我该怎么做呢?
HTML,身体{
保证金:0;
填充:0;
背景:#a9ac41;
背景图像:网址(background.png);
背景重复:不重复;
背景大小:盖;
保证金:0;
填充:0;
}
我猜测,这里的问题是背景大小
。 IE8和更早版本不支持它,所以你看到你的形象在IE8搞砸了,你想恢复到一个普通的背景来解决它。
首先,我要告诉你,背景大小
支持在IE9及更高版本,所以你不必这样做,因为所有的IE版本毯子变化。你只有真正需要处理缺乏在IE8的支持和更早版本。
下面是一些选项供您:
-
纯CSS解决方案:
您可以利用的方式的CSS处理未知属性的为不支持背景大小
,通过指定大小作为一个参数的浏览器提供了一个纯CSS后备速记背景
风格:背景:#a9ac41;
背景:网址(bgimage.png)覆盖;IE8会忽略第二个
背景
完全是因为不理解覆盖
。因为第二个覆盖它其他浏览器会忽略第一个。问题解决了:所有的浏览器有一个工作的背景 -
特征检测解决方案:
你可以使用像 Modernizr的的工具来测试浏览器的支持背景大小
,然后使用Javascript来相应地更改页面(如果是如加载不同的样式表/不支持)。 -
过滤器
解决方案:
尽管IE8不支持背景大小
,也可以使用-ms过滤
属性效仿与某种程度的成功。你可以使用code是这样的:-ms过滤器进程id:DXImageTransform.Microsoft.AlphaImageLoader(SRC ='path_relative_to_the_HTML_file',sizingMethod ='规模');
从MDN 采取
-
填充工具的解决方案:
还有一些填充工具可用它实现一些缺失的CSS功能到老的IE版本,包括背景大小
脚本。在这种情况下,一个我建议是 CSS3Pie 。按照上css3pie网站上的指示,你就可以使用标准的背景大小
即使是在很老的IE版本。
希望有所帮助。
Here's the CSS , and I want the background picture not to be displayed in IE . Instead I just want the background color to be displayed. How do I do that?
html, body {
margin:0;
padding: 0;
background: #a9ac41;
background-image: url("background.png");
background-repeat: no-repeat;
background-size: cover;
margin:0;
padding: 0;
}
I'm guessing that the problem here is background-size
. IE8 and earlier don't support it, so you're seeing your image messed up in IE8 and you want to solve it by reverting to a plain background.
Firstly, I should tell you that background-size
is supported in IE9 and later, so you don't need to do this as a blanket change for all IE versions. You only really need to deal with the lack of support in IE8 and earlier.
Here are some options for you:
Pure CSS solution:
You can take advantage of the way CSS handles unknown properties to provide a pure CSS fallback for browsers that don't supportbackground-size
, by specifying the size as a parameter in a shorthandbackground
style:background: #a9ac41; background: url("bgimage.png") cover;
IE8 will ignore the second
background
entirely because doesn't understandcover
. Other browsers will ignore the first one because the second one overrides it. Problem solved: all browsers have a working background.Feature detection solution:
You could use a tool like Modernizr to test for browser support ofbackground-size
, and then use Javascript to change the page accordingly (eg load a different stylesheet if it is/isn't supported).filter
solution:
Although IE8 doesn't supportbackground-size
, it is possible to use the-ms-filter
property to emulate it, with some degree of success. You would use code like this:-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='path_relative_to_the_HTML_file', sizingMethod='scale')";
Example taken from MDN
Polyfill solution:
There are some 'polyfill' scripts available which implement some of the missing CSS features into old IE versions, includingbackground-size
. In this case, the one I'd recommend is CSS3Pie. Follow the instructions on the css3pie site and you'll be able to use standardbackground-size
even in very old IE versions.
Hope that helps.
这篇关于我想要的背景图片不被显示在IE。我怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!